Skip to content

Instantly share code, notes, and snippets.

@Lackoftactics
Created April 9, 2018 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lackoftactics/48bac08e5d12882032820a6a767ce720 to your computer and use it in GitHub Desktop.
Save Lackoftactics/48bac08e5d12882032820a6a767ce720 to your computer and use it in GitHub Desktop.
&method
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