From: Edgardo Hames Date: 2009-04-14T06:45:04+09:00 Subject: Re: a few thoughts for ruby... On Apr 11, 2:27 pm, Adam Gardner wrote: > Roger Pack wrote: > > Thought I'd pass these thoughts by the readers here before sending them > > to core.  They're my current wish list :) > > > 1) add an Object#in? method to complement the existing Array#include? > > Object#in? can be very useful in keeping code legible; it more likely to > be problematic in some circumstances than others. I'm using it in the > game I'm writing right now and it's working just fine, but I don't > really think it should be part of Ruby Core. > > That said, it's very very easy to add yourself if you need it: > > class Object >   def in?(object) >     if object.respond_to?(:include?) then >       object.include? self >     else >       false >     end >   end #def in? > end #class Object Before reading your email I was writing my own Object#in? and came up with a very similar method without testing :include? support: class Object def in?(collection) collection.include? self end end This way you can detect you're calling Object#in? with an "incorrect" argument. For example, 3.include? [1,2,3] => true 3.include? 5 => NoMethodError: undefined method `include?' for 5:Fixnum My $0.02. Best regards, Edgardo