Lambdas
Strict-arity procs.
Strict-Arity Procs
A lambda is a special kind of Proc that behaves more like a regular method: it checks its argument count and treats return normally. Use it when you want predictable, method-like behavior.
square = lambda { |x| x * x }
puts square.call(6)The Stabby Lambda
The arrow syntax ->, nicknamed the 'stabby lambda,' is the most common way to write lambdas. Parameters go in parentheses.
add = ->(a, b) { a + b }
puts add.call(4, 5)