Class: Algorithm::FollowEnumerator

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/shellopts/ext/follow.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, method = nil, &block) ⇒ FollowEnumerator

Returns a new instance of FollowEnumerator.



4
5
6
7
8
9
10
11
12
# File 'lib/shellopts/ext/follow.rb', line 4

def initialize(object, method = nil, &block)
  closure = method ? lambda { |object| object.__send__(method) } : block
  super() { |yielder|
    while object
      yielder << object
      object = closure.call(object)
    end
  }
end