From: Michael Fellinger Date: 2010-12-26T23:23:57+09:00 Subject: Re: converting traversal fn into Enumeration On Sun, Dec 26, 2010 at 7:27 PM, Brian Candler wrote: > Or there is class Enumerator in the standard library which you can use > (in 1.8 it's Enumerable::Enumerator). It just gives a wrapper object > which maps a call to :each to some other method in the underlying > object. > > require 'enumerator' > class TNode >  def traversal >    Enumerable::Enumerator.new(self, :traverse) >  end > end The usual way to return enumerators in 1.9 is this: def traverse return to_enum(__method__) unless block_given? loop{ yield(rand(10)) } end traverse.find{|e| e > 1 } # => 7 -- Michael Fellinger CTO, The Rubyists, LLC