Ruby parens-free function calls [was Re: Accessing parent objects]

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Mar 28 09:28:29 EDT 2018


On 2018年3月27日 11:34:17 +1100, Chris Angelico wrote:
> Question: How do you get a reference to a Ruby function? Or are they not
> first-class objects?

https://stackoverflow.com/questions/4294485/how-do-i-reference-a-function-
in-ruby
Especially this answer, which is worth reading:
https://stackoverflow.com/a/4294660
As best I can interpret it, Ruby starts with the premise that functions 
and methods are NOT first-class values -- or rather, since Ruby functions 
are actually methods of Object, there are no functions, only methods, and 
they are not first-class values.
obj.method, despite superficially looking like the same as Ruby's dot 
syntax for attribute access, actually is syntax for calling the method.
In practice, that's not as restrictive as it may seem. Where Python would 
pass a function object to a higher-order function, Ruby would usually 
pass an anonymous block or possibly a Proc.
-- 
Steve


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /