Afficher un message
Vieux 20/11/2007, 16h29   #12
Robert Klemme
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: is there an nicer way for this expression?

2007/11/20, Trans <transfire@gmail.com>:
>
>
> On Nov 20, 7:38 am, Remco Hh <re...@huijdts.nl> wrote:
> > hi,
> > perhaps a stupid question.
> >
> > i do this a lot: if (foo.bar==1 or foo.bar==2)
> >
> > can i make this expression shorter and nicer?,
> > something like if (foo.bar=1,2), which of course doesn't work

>
> One way:
>
> if [1,2].include?(foo.bar)
> # ...
> end
>
> another:
>
> case foo.bar when 1,2 then
> # ...
> end


Hey, this looks familiar! ;-)

Cheers

robert

--
use.inject do |as, often| as.you_can - without end

  Réponse avec citation
 
Page generated in 0,04839 seconds with 9 queries