From: Rick DeNatale Date: 2008-01-05T05:11:46+09:00 Subject: Re: Checking an array for an item On Jan 4, 2008 11:25 AM, Giles Bowkett wrote: > > How come this code doesn't return "true" for the following? > > > > x = [1,2,3] > > > > puts(x.include?(Fixnum)) > To get what you want the best approach is map, or one of a few > functions similar to map, such as collect or inject: Well, if you're trying to find out if the array contains at least one Fixnum then this isn't really the best way. Instead I'd use x.any? {|obj| Fixnum === obj } which returns a single boolean, and only looks at as many elements of the array as it needs to. Alternately one could use x.find {|obj| Fixnum === obj } which will return either the first Fixnum in the array, or nil if their isn't one, which can be used the same way as a boolean value in almost all cases. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/