From: dblack@... Date: 2006-09-28T23:14:58+09:00 Subject: Re: New magical version of Symbol.to_proc Hi -- On Thu, 28 Sep 2006, Robert Dober wrote: > >> >> >> >>> (1..10).to_a.to_ss >> > => ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] >> >>> (1..10).to_a.days >> > => [86400, 172800, 259200, 345600, 432000, 518400, 604800, 691200, >> > 777600, 864000] >> >>> [2,'two', :two].classes >> > => [Fixnum, String, Symbol] >> >>> [2,'two', :two].classes.names >> > => ["Fixnum", "String", "Symbol"] >> >>> [2,'two', :two].classes.names.lengths >> > => [6, 6, 6] >> > >> > So much happy syntax in one place! >> >> Actually the reason this is kind of cool is not the syntax but the >> semantics. It's much more expressive than any number of &:->()... >> things that have been proposed -- and looks better. (There may be >> some connection there too.) >> >> I wonder, though, whether it would be too easy for it to trample on >> other method names. I guess that's true of anything -- you'd just >> have to make sure you didn't have two conceptions of some plural >> thing. > > > I agree, *cool* and *somehow dangerous*, I would very conservatively propose > a proxy method, similiar in spirit to BDD's rspec#is > > %w{the meaning of 42}.map.length => [3, too_long_to_count, 2, 2] > > or maybe not overload #map without params for that purpose? I personally dislike "magic dot" stuff like that. True, it's not really magic, since map can return some kind of enumerator that knows about the array and is ready to do something to it. But it still has the look and feel of a kind of secret system for communicating what's wanted, rather than something that really makes sense when read left to right. That's why I prefer Dr. Nic's plurals thing, though it definitely has the disadvantage of entering into murky territority in terms of method naming. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org