How does Ruby compare to Python?? How good is DESIGN of Rubycompared to Python?

Joe Mason joe at notcharles.ca
Thu Feb 26 17:00:57 EST 2004


In article <Xns949B61515EFD1duncanrcpcouk at 127.0.0.1>, Duncan Booth wrote:
> Say I modify your example so that we only have one Func which accepts 
> either a bound or unbound (functionCallback and Foo definitions are 
> unchanged):
> 
>>>> def Func(callback, *extra_args):
>         print callback(*(extra_args+(5,6)))
> 
>         
>>>> Func(functionCallback)
> 11
>>>> f = Foo()
>>>> f.setc(3)
>>>> Func(f.methodCallback)
> 33
>>>> Func(Foo.methodCallback, f)
> 33
>>>> 
> 
> Python doesn't care what type of callable it is passed, so long as it 
> somehow ends up with the right arguments to call it. Can Ruby handle this 
> case?

Sure, you'd just have to check if "callback" is of class Method or
UnboundMethod, and call bind on the first member of extra_args if
necessary.  Again, Python does this for you, so it's definitely a
difference in the language, but it's not impossible (or even difficult).

With Ruby, you'd probably use blocks instead of functions for most
things that need this anyway.

Joe



More information about the Python-list mailing list