On 18.01.2008 20:11, Justin Collins wrote:
> Radosaw Buat wrote:
>> In python when you use method name without parenthesises you get
>> method reference. In Ruby it won't work beacuse method can be called
>> without parenthesises (and Ruby programmers love it :)). If you want
>> to get method reference you can use method(:you_method_name) and you
>> get reference to Method instance. Later you can just call 'call'
>> method and pass some parameters. Direct traslation of your program to
>> Ruby looks like:
>>
>> def firstWay(arg1, arg2)
>>   return 'Tastes great.'
>> end
>>
>> def secondWay(arg1, arg2)
>>   return 'Less filling.'
>> end
>>
>> def doStuff(whichway, first_arg, second_arg)
>>   return whichway.call(first_arg, second_arg)
>> end
>>
>> puts doStuff(method(:firstWay), nil, nil
> 
> Ah, that's the one I was looking for.  Then you can do:
> 
> def doStuff(whichway, first_arg, second_arg)
>   whichway[first_arg, second_arg]
> end

Yeah, but do you really consider

doStuff(method(:firstWay), nil, nil)

more concise than

send(:firstWay, nil, nil)

?

Cheers

	robert