From: Robert Klemme Date: 2013-03-26T06:58:30+09:00 Subject: Re: Confusion with Array#map On Mon, Mar 25, 2013 at 7:41 PM, tamouse mailing lists wrote: > On Mon, Mar 25, 2013 at 1:37 PM, Love U Ruby wrote: >> How `proc` object is getting called by `call` to produce the output? Who >> is calling that? > > The operator "&" is the block operator, which is turning the symbol > :capitalize which refers to the method capitalize in that context. > Since at that point, map is sending in strings, it says to call the > capitalize method on that string. > https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls#The_Ampersand_Operator The crucial bit here is that Symbol#to_proc exists. Actually anything can be used in that way: irb(main):001:0> o = Object.new => # irb(main):002:0> def o.to_proc; lambda {|x| "<#{x.inspect}>"} irb(main):003:1> end => nil irb(main):004:0> (1..5).map(&o) => ["<1>", "<2>", "<3>", "<4>", "<5>"] Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/