1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-07 00:58:02 +00:00

Add Passing Arbitrary Methods As Blocks as a ruby til.

This commit is contained in:
jbranchaud
2015-07-28 21:31:03 -05:00
parent efd1aa3ea0
commit a9dcbe303c
2 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
# 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]
```