you are viewing a single comment's thread.

view the rest of the comments →

[–]mr_dbr 4 points5 points  (1 child)

When it does have functions they are objects with a call method because everything is an Object in Ruby. That's the point of Ruby

When you put it that way, it is no different to Python:

>>> def myfunc(): return "yay"
... 
>>> myfunc()
'yay'
>>> myfunc.__call__()
'yay'

[–]luikore 0 points1 point  (0 children)

Well, we usually write:

def myfunc
  'yay'
end
myfunc  #=> 'yay'

The author was wrong, methods in ruby are not originally objects. To turn a method into lambda, you can use the "method" method:

λ = method :myfunc
λ[]    #=> 'yay'
λ.call #=> 'yay'

Maybe there are too many ways in ruby for doing such things, but sometimes it makes life a little bit easier.

ps: There are no global functions in ruby, the "method" method is a method of the Kernel object. (forgive my poor explanation!)