From: Josselin Date: 2006-08-12T15:05:09+09:00 Subject: Re: good writing in Ruby... On 2006-08-11 08:39:25 +0200, "Martin DeMello" said: > On 8/11/06, Josselin wrote: >> On 2006-08-10 22:01:38 +0200, Chad Perrin said: >> >> > On Fri, Aug 11, 2006 at 01:20:08AM +0900, 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" ] >> > >> > Do the "roles" have to be those letters, or did you just use them to >> > illustrate what you're doing? If you can use numbers for "roles" >> > instead, a whole new realm of possibilities opens up using comparison >> > operators. >> >> yeah see my answer to Daniel... I believe adding an integer priority >> field will be easier (sure.. if I need to add new roles later...) >> thanks > > You could make a Role class, define a <=> operator and mix in Comparable. > > martin thanks Martin, that's what I finally did... writing my own Role class (the original one was part of an authorization plugin... did not have some much control over it ) joss