Class: Enumerable::Enumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
enumerator.c,
enumerator.c

Overview

A class which provides a method ‘each’ to be used as an Enumerable object.

Instance Method Summary collapse

Methods included from Enumerable

#all?, #any?, #collect, #count, #cycle, #detect, #drop, #drop_while, #each_cons, #each_slice, #entries, #enum_cons, #enum_slice, #enum_with_index, #find, #find_all, #find_index, #first, #grep, #group_by, #include?, #inject, #map, #max, #max_by, #member?, #min, #min_by, #minmax, #minmax_by, #none?, #one?, #partition, #reduce, #reject, #reverse_each, #select, #sort, #sort_by, #take, #take_while, #to_a, #zip

Constructor Details

#Enumerable::Enumerator.new(obj, method = :each, *args) ⇒ Object

Creates a new Enumerable::Enumerator object, which is to be used as an Enumerable object using the given object’s given method with the given arguments.

Use of this method is not discouraged. Use Kernel#enum_for() instead.



259
260
261
# File 'enumerator.c', line 259

static VALUE
enumerator_initialize(argc, argv, obj)
int argc;

Instance Method Details

#each { ... } ⇒ Object

Iterates the given block using the object and the method specified in the first place. If no block is given, returns self.

Yields:



314
315
316
# File 'enumerator.c', line 314

static VALUE
enumerator_each(obj)
VALUE obj;

#with_index {|(*args), idx| ... } ⇒ Object #with_indexObject

Iterates the given block for each elements with an index, which start from 0. If no block is given, returns an enumerator.

Overloads:

  • #with_index {|(*args), idx| ... } ⇒ Object

    Yields:

    • ((*args), idx)


350
351
352
# File 'enumerator.c', line 350

static VALUE
enumerator_with_index(obj)
VALUE obj;

#initialize_copyObject

:nodoc:



278
279
280
# File 'enumerator.c', line 278

static VALUE
enumerator_init_copy(obj, orig)
VALUE obj;

#nextObject

Returns the next object in the enumerator, and move the internal position forward. When the position reached at the end, internal position is rewinded then StopIteration is raised.

Note that enumeration sequence by next method does not affect other non-external enumeration methods, unless underlying iteration methods itself has side-effect, e.g. IO#each_line.

Caution: Calling this method causes the “generator” library to be loaded.

Returns:



384
385
386
# File 'enumerator.c', line 384

static VALUE
enumerator_next(obj)
VALUE obj;

#rewindObject

Rewinds the enumeration sequence by the next method.



399
400
401
# File 'enumerator.c', line 399

static VALUE
enumerator_rewind(obj)
VALUE obj;

#with_index {|(*args), idx| ... } ⇒ Object #with_indexObject

Iterates the given block for each elements with an index, which start from 0. If no block is given, returns an enumerator.

Overloads:

  • #with_index {|(*args), idx| ... } ⇒ Object

    Yields:

    • ((*args), idx)


350
351
352
# File 'enumerator.c', line 350

static VALUE
enumerator_with_index(obj)
VALUE obj;