Module: EventMachine::IteratorWithEnumerable

Included in:
Iterator
Defined in:
lib/patch/iterator.rb

Overview

Support for Enumerable in Ruby 1.9+

Instance Method Summary collapse

Instance Method Details

#next?Boolean

We can’t check just next_item as far as it can return nil in two cases: when our enumerator is stopped and when it stores nil value

Returns:

  • (Boolean)


57
58
59
60
61
62
63
64
65
66
# File 'lib/patch/iterator.rb', line 57

def next?
  begin
    @next_item = @list.next
    true
  rescue StopIteration
    false
  rescue => e
    raise e
  end
end

#next_itemObject



51
52
53
# File 'lib/patch/iterator.rb', line 51

def next_item
  @next_item
end

#setup_list(list) ⇒ Object

Raises:

  • (ArgumentError)


46
47
48
49
# File 'lib/patch/iterator.rb', line 46

def setup_list(list)
  raise ArgumentError, 'argument must be an Enumerable' unless list.respond_to?(:each)
  list.to_enum
end