From: Robert Klemme Date: 2007-11-20T21:47:55+09:00 Subject: Re: is there an nicer way for this expression? 2007/11/20, Pokkai Dokkai : > 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