Created
March 12, 2015 15:05
-
-
Save leoallen85/c0870b838bb2ba8fe716 to your computer and use it in GitHub Desktop.
Passing methods as arguments with Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def square(integer) | |
| integer * integer | |
| end | |
| [1,2,3].map(&method(:square)) # => [1,4,9] |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replicating this behaviour in Javascript: