Created
May 22, 2013 00:12
-
-
Save ashrithr/5624327 to your computer and use it in GitHub Desktop.
ruby &: usage
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
# 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