From: Mariano Kamp Date: 2006-10-04T01:26:12+09:00 Subject: Re: Using Each to Iterate Hi Jeff, On Oct 3, 2006, at 6:00 PM, ixnay wrote: > [..] > I have a class called StepList and in that class I have an each > method as > such: > > class StepList > def initialize > @guides = Array.new > end > def each > @guides.find { |guide| guide.filter } > end > end > Not sure what you are trying to accomplish here? "each" should return each filtered element? guide.filter returns true, when some conditions are met? Currently each would return the first element in guides that match "guide.filter". It also wouldn't make any use of a block you pass in. > If I put a "puts" in front of the guide.filter, I see that this is > working > correctly by just grabbing the values I want. Could you provide the full source code and the output of the running program? The puts would show you all the elements it will try to filter and as puts returns nil (think false) the whole list of guides will be tried before returning nothing. > However, the results are never > passed back. For example, I have this: > > $stepList.each { |thisFilter| > puts "test" > puts thisFilter > } > See above ... Your each doesn't care for a block... You don't call yield anywhere... > What I'm trying to do is get the value of each filter and have that > get > placed in thisFilter each time through the loop. What happens is that > nothing happens! I do not even see the "test" text get printed out. > Yet, it > seems the each must be looping because the guide.filter in my my > each method > does return values if I put a puts in front of it. Still not sure what you are trying to do? You want to be called with all the guides that match a certain criteria? I don't have the pickaxe handy, please refresh my memory what you are trying to do. Cheers, Mariano