From: rak rok Date: 2006-08-25T03:05:40+09:00 Subject: Re: do not understand this closure ------=_Part_104404_9389107.1156442730796 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Is there any way to have a proc object be callable identically to a method, ie with the parentheses? Is there a reason to keep the notation distinct? Thanks, -rr- On 8/24/06, Martin DeMello wrote: > > On 8/24/06, Dave Rose wrote: > > in The Ruby Way...chap 1...a crude example of closure doesn't work as > > this irb > > session: > > >> def power(exponent) > > >> proc {|base| base**exponent} > > >> end > > => nil > > >> square = power(2) > > => # > > >> cube = power(3) > > => # > > >> p square > > # > > => nil > > >> square(11) > > NoMethodError: undefined method `square' for main:Object > > from (irb):7 > > You want square[11] or square.call(11) > > square(11) is interpreted as "call the method 'square' on the current > "self" object, with the argument '11'", whereas square[11] is > interpreted as "call the method [] on the object 'square' with the > argument 11. Proc defines [] to be a synonym of call. > > martin > > ------=_Part_104404_9389107.1156442730796--