3 ms·
Lambda makes Proc instances because Ruby is purely OO and every value you can get is an object. It might be nice if there were syntax that allowed you to treat
by vidarh 5y ago
Lambda makes Proc instances because Ruby is purely OO and every value you can get is an object. It might be nice if there were syntax that allowed you to treat an object as if it was a method, but it'd be tricky because of other Ruby syntax.
> Ah yeah Proc a bit like lambda but also not really.
lambda/-> creates a Proc instance (with an appropriate flag set). The distinction between lambda vs (lower case) "proc" is tricky until you consider that a "proc" is effectively just a shortcut to return a block as a value. The semantics of a block reified into a Proc instance by giving it a name, and a Proc instance created with "proc" are the same.
So you could implement your own "proc":
def make_proc(&block)
block
end
(in fact the above example is from the Ruby docs)