From: dblack@... Date: 2006-09-28T22:47:40+09:00 Subject: Re: New magical version of Symbol.to_proc Hi -- On Thu, 28 Sep 2006, Dr Nic wrote: >>> list.map &:to_i > => [1, 2, 3] > > It works. Just enjoy it. (see article for links on why it works) It's not my favorite construct; it's a bit ugly and terse in a bad way. You mentioned elsewhere that this is going to be in 1.9, though I remember Matz rejecting an RCR for: list.map(:to_i) and &:to_i seems worse :-) >>> (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. 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