seeker
seeker

Reputation: 558

Why is `next` not listed as a method of the `Enumerator` class?

The following methods are listed on the documentation page for the Enumerator class:

However when I do the following in irb I receive false:

>> Enumerator.methods.include?(:next)
false

Is this because even though the method can be used on instances of this class, the method isn't explicitly defined on the class itself, i.e. it is inherited? Having thought this I also checked Enumerator superclasses and found that they do not contain this method either:

>> Enumerator.superclass.methods.include?(:next)
false
>> Enumerator.superclass.superclass.methods.include?(:next)
false

I'm sure I'm overlooking something quite fundamental..

Upvotes: 2

Views: 51

Answers (1)

Rupert Saxton
Rupert Saxton

Reputation: 84

#next is an instance method of the Enumerator class. Using Enumerator.instance_methods.include?(:next) will return true

Upvotes: 5

Related Questions