From: "David A. Black" Date: 2008-06-14T04:24:48+09:00 Subject: [ruby-core:17241] Re: Enumerable::Enumerator#with_memo Hi -- On Sat, 14 Jun 2008, Jeremy Kemper wrote: > On Fri, Jun 13, 2008 at 8:28 AM, Akinori MUSHA wrote: >> Thank you all for your voices! >> >> At Wed, 4 Jun 2008 03:28:03 +0900, >> I wrote: >>> with_object: >>> - not bad, but too unspecific and a bit too long to use often >> >> On second thoughts, `with_object' sounds just fine and simply better >> than with_memo. A method that does many things deserves a long name, >> with the word `object' giving a user an impression that passing an >> immutable object may be useless. >> >> So, I'd take `with_object' as the safest choice. >> >> >> Among your opinions and ideas, I personally liked `returning', but it >> is too bad it does not say anything about adding a parameter. >> >> Let me note, as a few people already pointed out, that making method >> chains `readable' as English is not a requisite here. Making Ruby >> sound like English makes things at some points in some use cases >> easier, but going too far it often spoils simplicity, intuitiveness >> and consistency. >> >> >> Now, I was so inspired by your options such as `traverse_with' and >> `subject' (as a noun), but I'm still thinking that there could be a >> better one word verb. Here are some I thought up. >> >> bring: >> -- brings an object through the iteration (back to where it was) >> >> introduce: >> -- introduces an object to the block and to the whole expression >> (implying that the object is the subject, i.e. return value) > > I think introduce is very good name. > > * it's a verb describing the same behavior as with_object > * it's more succinct, in the spirit of map, select, inject > * it's obvious that it introduces a block param > * it implies that the introduced arg will be the return value Wouldn't the return value depend on the method you're chaining it to though, like with_index? For example, I would expect this: [1,2,3].map.introduce(obj) {|a,b| ... } to return not obj but a mapping of [1,2,3]. Similarly, this: [1,2,3].select.introduce(obj) {|a,b| } I would expect to return a selected subset of [1,2,3]. I'm probably vastly misunderstanding the whole point of the method. I think I'm in favor of the bland but congruent with_object. The nearness of with_index and with_object appeals to me, especially given how many new terms and naming idioms there are in 1.9 already. David -- Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS June 16-19 Berlin ADVANCING WITH RAILS July 21-24 Edison, NJ See http://www.rubypal.com for details and updates!