Created
October 25, 2013 02:54
-
-
Save kjirou/7148790 to your computer and use it in GitHub Desktop.
Procとlambdaの挙動の違いの一部 Ref) http://d.hatena.ne.jp/shunsuk/20090101/1230816826
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
def proc_return | |
Proc.new { return "In Proc.new" }.call | |
return "proc_return method finished" | |
end | |
def lambda_return | |
lambda { return "In lambda" }.call | |
return "lambda_return method finished" | |
end | |
# Proc は return が出てくると強制的に終わる | |
# lambda は そうではなく普通の関数っぽく動く | |
puts proc_return # -> "In Proc.new" | |
puts lambda_return # -> "lambda_return method finished" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment