1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-04 23:58:01 +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

@@ -112,6 +112,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
- [Listing Local Variables](ruby/listing-local-variables.md)
- [Override The Initial Sequence Value](ruby/override-the-initial-sequence-value.md)
- [Parallel Bundle Install](ruby/parallel-bundle-install.md)
- [Passing Arbitrary Methods As Blocks](ruby/passing-arbitrary-methods-as-blocks.md)
- [Percent Notation](ruby/percent-notation.md)
- [Question Mark Operator](ruby/question-mark-operator.md)
- [Squeeze Out The Extra Space](ruby/squeeze-out-the-extra-space.md)

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]
```