From: Eero Saynatkari Date: 2009-05-24T00:47:19+09:00 Subject: [ruby-core:23528] Re: [Bug #1487] String#each_char must return self Excerpts from Yukihiro Matsumoto's message of Sat May 23 18:34:35 +0300 2009: > Hi, > > In message "Re: [ruby-core:23526] Re: [Bug #1487] String#each_char must return > self" > on Sun, 24 May 2009 00:00:52 +0900, Eero Saynatkari writes: > > |> I was hoping for a little bit of consistency as well. > | > |Also true for Array#each and so on. Whichever way it goes, > |they should all be the same. > | > |Philosophically, returning self from a non-mutating iterator > |is the most straightforward thing to do and makes it possible > |to avoid the cost of the dup. > > The string may be modified in the block, so that you cannot avoid the > cost of the dup in this case. OK, consistency is the reason? What else? I suppose this is true, although I am in the "enough String to hang themselves" camp on the matter if someone thinks it a good idea to muck with the object being iterated on (and not using a mutating iterator.) The user can always do the dup themselves. Might it warrant a mention in the method documentation? -- Magic is insufficiently advanced technology.