From: Dhruva Sagar Date: 2010-09-03T11:09:41+09:00 Subject: Re: Enumerator#each return value is surprising --00c09f8c21f7df550e048f5169a3 Content-Type: text/plain; charset=UTF-8 Hi, ruby-1.9.1-p378 > e = [1,2,3].enum_for(:each) => # ruby-1.9.1-p378 > e.each {} => [1, 2, 3] ruby-1.9.1-p378 > e.each {|i| p i} 1 2 3 => [1, 2, 3] I think it's working just as one would expect it to...what you see as the return value at the end is 'e' itself. -- Thanks & Regards, Dhruva Sagar. On Fri, Sep 3, 2010 at 06:57, Christopher Dicely wrote: > 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_for(: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.? > > --00c09f8c21f7df550e048f5169a3--