May I think like this, Enumerator.new is a short way, including two
steps:
eg = Enumerator::Generator.new {|y| y << 1 }
p eg # #<Enumerator::Generator:0xb44890>
e1 = Enumerator.new(eg)
p e1 # #<Enumerator: #<Enumerator::Generator:0xb44890>:each>
e2 = eg.to_enum
p e2 # #<Enumerator: #<Enumerator::Generator:0xb44890>:each>
so ruby-doc says there are two forms of Enumerator.new:
Enumerator.new(obj, method = :each, *args)
Enumerator.new { |y| ... }
in fact, there's just one, the second one can be regarded as
Enumerator.new(enum_generator_instance)
Does Enumerator::Generator exist, because Ruby 1.8 has a Generator
class?
--
Posted via
http://www.ruby-forum.com/.