From: Ryan Davis Date: 2010-09-03T11:57:18+09:00 Subject: Re: Enumerator#each return value is surprising On Sep 2, 2010, at 19:09 , Dhruva Sagar wrote: > 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. No, it isn't. 'e' itself was output on the second line of your irb session. What each is returning is what 'e' is wrapping up, the array. That said, I think the result is as it should be, as enumerators should be (in my mind at least) acting as stand-ins for the real thing, they should be substitutable with the real thing and wind up with the same result: > >> a = [1, 2, 3] > => [1, 2, 3] > >> a.each {} > => [1, 2, 3] > >> e = a.enum_for(:each) > => # > >> e.each {} > => [1, 2, 3] I think that is a nice amount of symmetry.