Pascal J. Bourguignon wrote:
Ruby doesn’t work like that.
irb(main):033:0> plus4 = lambda { |x| x + 4}
plus4 = lambda { |x| x + 4}
#Proc:0x00325230@:33(irb)
irb(main):034:0> (plus4 2)
(plus4 2)
NoMethodError: undefined method `plus4’ for main:Object
from (irb):34
irb(main):035:0>
plus4.call(2), or more briefly, plus4[2]
Yes, a variable holding a lambda is a different beast to a method. As
you said, methods are associated with objects, and lambdas are not.
Usually one suits the usage case better than the other.
I find the distinct behaviours of both to be very useful in practice.