mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
16 lines
287 B
Markdown
16 lines
287 B
Markdown
# Passing Arbitrary Methods As Blocks
|
|
|
|
Use
|
|
[`Object#method`](http://ruby-doc.org/core-1.8.7/Object.html#method-i-method)
|
|
to create a callable `Method` object that can be passed to methods
|
|
that yield to a block.
|
|
|
|
```ruby
|
|
def inc(x)
|
|
x + 1
|
|
end
|
|
|
|
[1,2,3].map(&method(:inc))
|
|
#=> [2,3,4]
|
|
```
|