Skip to content

Instantly share code, notes, and snippets.

@okram999
Created September 24, 2016 20:36
Show Gist options
  • Save okram999/e5af32bd015aa0307933405dc0c7664a to your computer and use it in GitHub Desktop.
Save okram999/e5af32bd015aa0307933405dc0c7664a to your computer and use it in GitHub Desktop.
# 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