From a9dcbe303c4d378b7736d112c722f5a68ccdbf9c Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 28 Jul 2015 21:31:03 -0500 Subject: [PATCH] Add Passing Arbitrary Methods As Blocks as a ruby til. --- README.md | 1 + ruby/passing-arbritrary-methods-as-blocks.md | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 ruby/passing-arbritrary-methods-as-blocks.md diff --git a/README.md b/README.md index 430a0af..667055d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/ruby/passing-arbritrary-methods-as-blocks.md b/ruby/passing-arbritrary-methods-as-blocks.md new file mode 100644 index 0000000..9baa895 --- /dev/null +++ b/ruby/passing-arbritrary-methods-as-blocks.md @@ -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] +```