From: Robert Klemme Date: 2012-02-24T22:22:58+09:00 Subject: Re: cheered to soon enumerable woos On Fri, Feb 24, 2012 at 1:41 PM, Catsquotl wrote: > Thank you, > > After reading your post i took another look at what i was trying to do. > As i am just playing with different ide's, different irb setups and Rspec > testing. I missed what exactly was happening. Please post a http://sscce.org/ otherwise people have a hard time providing help. We can't read minds. > I had hoped to be able to use include? to return true even on a substring. > It does not do so in Arrays. > Also i wanted my search method to return either true or false, but with the > each(&block) coded as it is > the search method will return the entire array defined in each >  rendering my result.should == true or false useless... > > Anyway I settled on the following. > > >  def each(&block) >    [@afk, @name, @chname, @locatie, @aard, @actie].flatten.each(&block) >  end There is still self missing at the end of this method. >  def search str >     self.each do|n| >       if n.match(str) then >         return true >       end >     end >  end There is Enumerable#any? def search str any? {|n| n.match(str)} end > I do have the notion that search could be changed to return true or false, > but this way i can test whether it is true or not_true. > And the class does what it needs to do... Do not rely on "true" and "false" used as boolean values. Rather directly evaluate the value in a boolean context. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/