Ruby 3 · Blocks, classes and pattern matching

Create a lambda

A lambda is a callable object that checks its arguments.

double = ->(n) { n * 2 }
puts double.call(4)
puts [1, 2, 3].map(&double).inspect

Official Ruby 3 documentation

More blocks, classes and pattern matching commands

All blocks, classes and pattern matching commands · Ruby 3 cheatsheet

Was this page helpful?