Robert Klemme
11/20/2007 12:48:00 PM
2007/11/20, Pokkai Dokkai <bad_good_lion@yahoo.com>:
> Remco Hh 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 :)
> >
> > regards,
> >
> > remco
>
> foo.bar == 1 || 2
Sure? Did you test this?
$ ruby -e '5.times {|foo| p [foo, foo == 1 || 2]}'
[0, 2]
[1, true]
[2, 2]
[3, 2]
[4, 2]
All cases are non nil and non false => true.
robert
--
use.inject do |as, often| as.you_can - without end