Created
February 18, 2009 10:32
-
-
Save vangberg/66290 to your computer and use it in GitHub Desktop.
lambda v proc v Proc.new
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
In 1.8 proc == lambda && proc != Proc.new | |
In 1.9 proc == Proc.new && proc != lambda |
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
l = lambda {|a,b| a + b} | |
p = proc {|a,b| a + b} | |
pr = Proc.new {|a,b| a + b} | |
## 1.8 | |
l[1,2,3] | |
#=> ArgumentError: wrong number of arguments (3 for 2) | |
p[1,2,3] | |
#=> ArgumentError: wrong number of arguments (3 for 2) | |
pr[1,2,3] | |
#=> 3 | |
## 1.9 | |
l[1,2,3] | |
#=> ArgumentError: wrong number of arguments (3 for 2) | |
p[1,2,3] | |
#=> 3 | |
pr[1,2,3] | |
#=> 3 |
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
def lamby | |
f = lambda {return "from lambda!"} | |
f.call | |
return "from method!" | |
end | |
def procy | |
f = proc {return "from proc!"} | |
f.call | |
return "from method!" | |
end | |
def proc_new | |
f = Proc.new {return "from Proc.new!"} | |
f.call | |
return "from method!" | |
end | |
## 1.8 | |
lamby #=> from method! | |
procy #=> from method! | |
proc_new #=> from Proc.new! | |
## 1.9 | |
lamby #=> from method! | |
procy #=> from proc! | |
proc_new #=> from Proc.new! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment