mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Fix a typo in the name of the latest til file.
This commit is contained in:
15
ruby/passing-arbitrary-methods-as-blocks.md
Normal file
15
ruby/passing-arbitrary-methods-as-blocks.md
Normal 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]
|
||||
```
|
||||
Reference in New Issue
Block a user