Created
September 24, 2016 20:36
-
-
Save okram999/e5af32bd015aa0307933405dc0c7664a to your computer and use it in GitHub Desktop.
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
# They both stores a block in a variable | |
#Differences: | |
1. Proc doesnt care the number of arguments passed | |
2. Proc exist out of a code block, when it meets 'return' while lambda processes return as moves on till 'end' | |
#Sample Proc | |
full_name = Proc.new {|first, last| first + " " + last} | |
p full_name["Jane", "Smith"] | |
#Sample Lambda | |
full_name = lambda{|first, last| first + " " + last} | |
p full_name["Jane", "Smith"] | |
#Another syntax for lambda in RoR aka stabby lambda | |
full_name = ->(first, last) {first + " " + last} | |
p full_name["Jane", "Smith"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment