4 ms·
What is the distinction between a function and a proc? I would say that a proc is a (first-class) function.
by djur 3y ago
What is the distinction between a function and a proc? I would say that a proc is a (first-class) function.
- e12e 3y agoAs I said, claiming that ruby doesn't have first-class functions isn't "meaningfully true". Ruby does not have functions, only methods. But that's mostly irrelevant. https://en.m.wikipedia.org/wiki/First-class_function#Language_support https://en.m.wikipedia.org/wiki/First-class_function#Languag... > The identifier of a regular "function" in Ruby (which is really a method) cannot be used as a value or passed. It must first be retrieved into a Method or Proc object to be used as first-class data. The syntax for calling such a function object differs from calling regular methods. https://blog.appsignal.com/2018/09/04/ruby-magic-closures-in-ruby-blocks-procs-and-lambdas.html https://blog.appsignal.com/2018/09/04/ruby-magic-closures-in... > Ruby doesn’t have first-class functions, but it does have closures in the form of blocks, procs and lambdas. Blocks are used for passing blocks of code to methods, and procs and lambda’s allow storing blocks of code in variables.