Confessions of a Python fanboy

Chris Rebert clp2 at rebertia.com
Thu Jul 30 00:27:20 EDT 2009


On Wed, Jul 29, 2009 at 9:04 PM, alex23<wuwei23 at gmail.com> wrote:
> On Jul 30, 1:06 pm, r <rt8... at gmail.com> wrote:
>> 1.) No need to use "()" to call a function with no arguments.
>> Python --> "obj.m2().m3()" --ugly
>>   Ruby --> "obj.m1.m2.m3"  -- sweeet!
>> Man, i must admit i really like this, and your code will look so much
>> cleaner.
>
> How do you distinguish between calling a method with no arguments, and
> getting access to the method object itself (because it _is_ an object,
> y'know, it's OO all the way down...)?

IIRC from the Pickaxe, to get at a method object, you call a method on
the object whose specific job it is to return method objects.
Unsurprisingly, this method is itself named "method". So:

foo.bar #calls the "bar" method on foo
foo.method(:bar) #returns the method "bar" of foo, as an object

Cheers,
Chris
-- 
http://blog.rebertia.com



More information about the Python-list mailing list