Created
March 26, 2015 15:36
-
-
Save sk187/4bab7e902b726c0e21e9 to your computer and use it in GitHub Desktop.
Passing Ruby Methods as a Proc
This file contains 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
#You can pass Ruby methods like a Proc | |
#Non Proc Example | |
numbers = [1,2,3,4,5] | |
string_numbers = numbers.map{ |number| number.to_s} | |
#Returns | |
["1","2","3","4","5"] | |
#Proc Example | |
numbers = [1,2,3,4,5] | |
string_numbers = numbers.map(&:to_s) | |
#Returns | |
["1","2","3","4","5"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment