rewind

e.rewind â e Instance Public methods Rewinds the enumeration sequence to the beginning. If the enclosed object responds to a ârewindâ method, it is called.

peek_values

e.peek_values â array Instance Public methods Returns the next object as an array, similar to #next_values, but doesn't move the internal position forward. If the position is already at the end, StopIteration is raised. Example o = Object.new def o.each yield yield 1 yield 1, 2 end e = o.to_enum p e.peek_values #=> [] e.next p e.peek_values #=> [1] p e.peek_values #=> [1] e.next p e.peek_values #=> [1, 2] e.next p e.peek_values # raises StopIter

peek

e.peek â object Instance Public methods Returns the next object in the enumerator, but doesn't move the internal position forward. If the position is already at the end, StopIteration is raised. Example a = [1,2,3] e = a.to_enum p e.next #=> 1 p e.peek #=> 2 p e.peek #=> 2 p e.peek #=> 2 p e.next #=> 2 p e.next #=> 3 p e.peek #raises StopIteration

old_inspect

old_inspect() Instance Public methods Alias for: inspect

next_values

e.next_values â array Instance Public methods Returns the next object as an array in the enumerator, and move the internal position forward. When the position reached at the end, StopIteration is raised. This method can be used to distinguish yield and yield nil. Example o = Object.new def o.each yield yield 1 yield 1, 2 yield nil yield [1, 2] end e = o.to_enum p e.next_values p e.next_values p e.next_values p e.next_values p e.next_values e = o.to_enum p e.next p e.n

next

e.next â object Instance Public methods Returns the next object in the enumerator, and move the internal position forward. When the position reached at the end, StopIteration is raised. Example a = [1,2,3] e = a.to_enum p e.next #=> 1 p e.next #=> 2 p e.next #=> 3 p e.next #raises StopIteration Note that enumeration sequence by next does not affect other non-external enumeration methods, unless the underlying iteration methods itself has side-effect, e.g. IO#e

inspect

e.inspect â string Instance Public methods Creates a printable version of e. old_inspect

feed

e.feed obj â nil Instance Public methods Sets the value to be returned by the next yield inside e. If the value is not set, the yield returns nil. This value is cleared after being yielded. o = Object.new def o.each x = yield # (2) blocks p x # (5) => "foo" x = yield # (6) blocks p x # (8) => nil x = yield # (9) blocks p x # not reached w/o another e.next end e = o.to_enum e.next #

each_with_object

e.with_object(obj) {|(*args), obj| ... }e.with_object(obj) Instance Public methods Iterates the given block for each element with an arbitrary object, obj, and returns obj If no block is given, returns a new Enumerator. Example to_three = Enumerator.new do |y| 3.times do |x| y << x end end to_three_with_string = to_three.with_object("foo") to_three_with_string.each do |x,string| puts "#{string}: #{x}" end # => foo:0 # => foo:1 # => foo:2

each_with_index

e.each_with_index {|(*args), idx| ... }e.each_with_index Instance Public methods Same as #with_index, i.e. there is no starting offset. If no block is given, a new Enumerator is returned that includes the index.