Created
April 9, 2018 09:31
-
-
Save Lackoftactics/48bac08e5d12882032820a6a767ce720 to your computer and use it in GitHub Desktop.
&method
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
In Ruby, &method passes you! | |
Most Rubyists would know what the following does. | |
[1, 2, 3].map(&:to_s) | |
It takes the array of numbers, calls to_s on each item, and returns an array of the return values. | |
But what if you want to do the opposite? Rather than calling a method on the object, what if you want to call a method with the object as a parameter? Simple! | |
["1", "2", "3"].map(&method(:Integer)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment