Skip to content

Instantly share code, notes, and snippets.

@ashrithr
Created May 22, 2013 00:12
Show Gist options
  • Save ashrithr/5624327 to your computer and use it in GitHub Desktop.
Save ashrithr/5624327 to your computer and use it in GitHub Desktop.
ruby &: usage
# Ruby has the & operator which can be used to "cast" any object to a block.
# This behaviour works out-of-the-box on Procs, Methods, and Symbols.
#Code below is equivalent
["1", "2", "3"].map{ |string| string.to_i }
#=> [1, 2, 3]
["1", "2", "3"].map(&:to_i)
#=> [1, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment