Last active
August 29, 2015 14:24
-
-
Save jgaskins/9817fd2c653a0a6ae91f to your computer and use it in GitHub Desktop.
Ruby proc vs lambda return
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 proc_return(enum) | |
l = proc { |x| return x * 2 } | |
enum.map { |i| l[i] } | |
end | |
def lambda_return(enum) | |
l = lambda { |x| return x * 2 } | |
enum.map { |i| l[i] } | |
end | |
array = [1, 2, 3] | |
p proc_return(array) # => 2 | |
p lambda_return(array) # => [2, 4, 6] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment