From: Wayne Magor Date: 2007-11-22T01:35:15+09:00 Subject: Re: is there an nicer way for this expression? 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 Not a stupid question at all. Many people want this in Ruby! Here's the solution (which should be standard in Ruby): class Object def in?(an_array) an_array.include?(self) end end Then, your desire to have something like (foo.bar=1,2) would become: foo.bar.in?([1,2]) -- Posted via http://www.ruby-forum.com/.