From: 7stud -- Date: 2011-04-20T02:36:55+09:00 Subject: Re: How to use Enumerator::Generator in Ruby 1.9.2 Joey Zhou wrote in post #993744: > e = Enumerator.new do |y| > y << 1 > end > > p e #=> #:each> > > well, it seems that e is an Enumerator, but has an Enumerator::Generator > in it. I am confused what on earth Enumerator::Generator is. > It's that y thing, and it knows how to provide values to the enumerator when your code requests values from the enumerator. > Can I get > an object that can return "Enumerator::Generator" if I type "obj.class"? > Let's see: 1) obj = Enumerator::Generator.new puts obj.class --output:-- prog.rb:1:in `initialize': no block given (LocalJumpError) from prog.rb:1:in `new' from prog.rb:1:in `
' 2) obj = Enumerator::Generator.new do |y| y << 1 end puts obj.class --output:-- Enumerator::Generator There you go. -- Posted via http://www.ruby-forum.com/.