From: Mauricio Fernandez Date: 2006-06-16T16:26:12+09:00 Subject: Re: Symbol#to_proc Problem On Fri, Jun 16, 2006 at 10:40:48AM +0900, Elliot Temple wrote: > it doesn't work for reversing arrays: > > curi-g5:~ curi$ ruby -v > ruby 1.8.4 (2005-12-24) [powerpc-darwin8.5.0] > > irb(main):017:0> class Symbol > irb(main):018:1> def to_proc > irb(main):019:2> Proc.new { |obj, *args| obj.send(self, *args) } > irb(main):020:2> end > irb(main):021:1> end > => nil > irb(main):022:0> [[1,2,3], [4,5,6], [7,8,9]].map {|i| i.reverse} > => [[3, 2, 1], [6, 5, 4], [9, 8, 7]] > > irb(main):023:0> [[1,2,3], [4,5,6], [7,8,9]].map &:reverse > NoMethodError: undefined method `reverse' for 1:Fixnum > from (irb):19:in `send' > from (irb):19:in `to_proc' > from (irb):23 > from (null):0 FYI the "official" implementation, recently added to Ruby 1.9, works that way too: $ ./ruby19 -v -e "p [[1,2,3], [4,5,6], [7,8,9]].map(&:reverse)" ruby 1.9.0 (2006-06-11) [i686-linux] -e:1: undefined method `reverse' for 1:Fixnum (NoMethodError) from -e:1 I read that Minero Aoki was against this being added to the core[1]; maybe it was for the reason you exposed. [1] http://mput.dip.jp/mput/?date=20060611#p01 -- Mauricio Fernandez - http://eigenclass.org - singular Ruby