Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #3202

Re: How to use Enumerator::Generator in Ruby 1.9.2

From Joey Zhou <yimutang@gmail.com>
Newsgroups comp.lang.ruby
Subject Re: How to use Enumerator::Generator in Ruby 1.9.2
Date 2011-04-19 21:23 -0500
Organization Service de news de lacave.net
Message-ID <4dd610eb5a6ed8425c11236449c7a032@ruby-forum.com> (permalink)
References <9bf8d8ed06528ddc8ebda9e54b79e232@ruby-forum.com>

Show all headers | View raw


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/.

Back to comp.lang.ruby | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How to use Enumerator::Generator in Ruby 1.9.2 Joey Zhou <yimutang@gmail.com> - 2011-04-19 01:43 -0500
  Re: How to use Enumerator::Generator in Ruby 1.9.2 Robert Klemme <shortcutter@googlemail.com> - 2011-04-19 02:44 -0500
    Re: How to use Enumerator::Generator in Ruby 1.9.2 Johannes Held <johannes.held@informatik.uni-erlangen.de> - 2011-04-19 12:55 +0200
      Re: How to use Enumerator::Generator in Ruby 1.9.2 Robert Klemme <shortcutter@googlemail.com> - 2011-04-19 07:01 -0500
  Re: How to use Enumerator::Generator in Ruby 1.9.2 Joey Zhou <yimutang@gmail.com> - 2011-04-19 07:49 -0500
    Re: How to use Enumerator::Generator in Ruby 1.9.2 7stud -- <bbxx789_05ss@yahoo.com> - 2011-04-19 12:36 -0500
  Re: How to use Enumerator::Generator in Ruby 1.9.2 Joey Zhou <yimutang@gmail.com> - 2011-04-19 21:23 -0500

csiph-web