Rubyの大域脱出(throw-catch)
throw-catchで大域脱出ができるらしい。
# coding: utf-8 str = catch :escape do loop do puts "ループ1" loop do puts "ループ2" throw :escape, "脱出" end end end puts str
実行結果は以下のとおり。
$ ruby throw-catch.rb ループ1 ループ2 脱出
throw-catchで大域脱出ができるらしい。
# coding: utf-8 str = catch :escape do loop do puts "ループ1" loop do puts "ループ2" throw :escape, "脱出" end end end puts str
実行結果は以下のとおり。
$ ruby throw-catch.rb ループ1 ループ2 脱出