1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 15:18:01 +00:00
Files
til/ruby/passing-arbitrary-methods-as-blocks.md
2015-07-28 21:32:09 -05:00

287 B

Passing Arbitrary Methods As Blocks

Use Object#method to create a callable Method object that can be passed to methods that yield to a block.

def inc(x)
  x + 1
end

[1,2,3].map(&method(:inc))
#=> [2,3,4]