From: Paolo Negri Date: 2006-08-11T01:37:18+09:00 Subject: Re: good writing in Ruby... Some more infos about what are the relations among the User class and the roles array would be nice. Anyway you can easily rewrite your role= method of the User class to something like this def role=(value, array) self.role = array.delete value if array.member? value end or, if you are happy to end up with a role of nil in case the role is invalid/already given away def role=(value, array) self.role = array.delete value end On 10/08/06, Josselin wrote: > I know I can write it the 'ugly common way' (loop) > but I'd like to see how it can be done the Ruby way ... (I am a newbie...) > > here is an array > roles = [ "a", "b", "c", "d", "e" ] > > Depending upon a variable 'user.role', > I would like to suppress all elements in the array , less or equal to > this variable > > ex : > user.role = "a" #=> roles = ["b", "c", "d", "e" ] "a" deleted > user.role = "b" #=> roles = ["c", "d", "e" ] "a", "b" deleted > user.role = "c" #=> roles = [ "d", "e" ] "a", "b", "c" deleted > user.role = "d" #=> roles = [ "e" ] "a", "b", "c", "d" deleted > user.role = "e" # do nothing > > thanks for your tips > > Joss > (I am on my way to buy the Ruby Recipes PDF Cookbook...) > > >