From: dblack@... Date: 2006-07-21T20:30:26+09:00 Subject: opacity of magic enumerator (was: Re: Using .each with constructors) Hi -- On Fri, 21 Jul 2006, Logan Capaldo wrote: > > On Jul 20, 2006, at 7:32 PM, transfire@gmail.com wrote: > >> Hmm...It's too bad that #times below returns 3. It be pretty neat if it >> acted like #map in this respect instead. >> >> 3.times { Object.new } >> > > irb(main):001:0> RUBY_VERSION > => "1.9.0" > irb(main):002:0> a, b, c = 3.times.map { Object.new } > => [#, #, #] Interesting.... That reveals that one of the problems with this magic enumerator thing is that the method names weren't necessarily chosen with this in mind, and don't work very well. 3.times.map very strongly does *not* communicate a 0...3 mapping to me. My first reading is: 3.map since I expect 3.times to return 3. My second reading is: 3.times { map { Object.new } } which also makes no sense. It's quite a leap to figure out that it means: (0...3).map { Object.new } I fear the magic enumerator doesn't sit very well with the language as designed without it. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy http://www.manning.com/black => RUBY FOR RAILS (reviewed on Slashdot, 7/12/2006!) http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log dblack@wobblini.net => me