As far as I understand the Array class already mixes in the Enumerable module.
If that's so, why isn't there [:example].next
?
Why do I need to make it [:example].to_enum.next
?
As far as I understand the Array class already mixes in the Enumerable module.
If that's so, why isn't there [:example].next
?
Why do I need to make it [:example].to_enum.next
?
to_enum
has nothing to do with Enumerable
, it returns an Enumerator
. Array
doesn't have a next
method because next
is an Enumerator
method, not an Enumerable
method.
Because the Enumerable
module is different from the Enumerator
class.
Being "Enumerable" means that the class gets a bunch of freebie methods that create "Enumerators". Compare to Java's Iterable
and Iterator
interfaces.