Class: Iterator
- Inherits:
-
Enumerator
- Object
- Enumerator
- Iterator
- Defined in:
- lib/mug/iterator_c.rb
Overview
A special class of Enumerator that repeatedly invokes a method.
Initially the method is send to the given obj
, but subsequent invocations are sent to the result of the previous invocation.
Example:
0.iter_for(:next).take(5) #=> [0,1,2,3,4]
Instance Method Summary collapse
-
#initialize(obj, meth, *args) ⇒ Iterator
constructor
Creates a new Iterator for method
meth
, to be called initially on objectobj
.
Methods inherited from Enumerator
Constructor Details
#initialize(obj, meth, *args) ⇒ Iterator
Creates a new Iterator for method meth
, to be called initially on object obj
.
All method calls will have args
as parameters.
19 20 21 22 23 24 25 26 |
# File 'lib/mug/iterator_c.rb', line 19 def initialize obj, meth, *args super() do |y| loop do y << obj obj = obj.send(meth, *args) end end end |