C
Christopher Dicely
Generally in Ruby, if enum is an Enumerable, enum.each returns enum --
this seems to be the case for all enums. But for Enumerator, it seems
to return...well, something else. For enumerators created with
enum_for, it returns the return value of the underlying function,
e.g.:
irb(main):065:0> e = [1,2,3].enum_foreach)
=> #<Enumerator: [1, 2, 3]:each>
irb(main):066:0> e.each {}
=> [1, 2, 3]
While the return value of each is usually not that important (its
usually used as if it was a procedure rather than for its return
value), shouldn't Enumerator#each return the receiver like Array#each,
Hash#each, etc.?
this seems to be the case for all enums. But for Enumerator, it seems
to return...well, something else. For enumerators created with
enum_for, it returns the return value of the underlying function,
e.g.:
irb(main):065:0> e = [1,2,3].enum_foreach)
=> #<Enumerator: [1, 2, 3]:each>
irb(main):066:0> e.each {}
=> [1, 2, 3]
While the return value of each is usually not that important (its
usually used as if it was a procedure rather than for its return
value), shouldn't Enumerator#each return the receiver like Array#each,
Hash#each, etc.?