Created
January 24, 2016 10:30
-
-
Save taisyo7333/43728fca816bdcbfa545 to your computer and use it in GitHub Desktop.
Ruby throw - catch
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
# encoding: utf-8 | |
def bar | |
catch(:calc) do | |
throw :calc , 100 | |
end | |
end | |
p bar | |
# => 100 |
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
e>ruby Code3-166.rb | |
ruby Code3-166.rb | |
100 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
throw に渡した第2引数 100 (値)をcatchの戻り値とできる。
どうやら値に限るらしい。