ä»æ¥è¦ã¤ããã³ã¼ã
ãªãã ãã®rescueã¨æã£ããã
def foo # å¦ç rescue LoadError # ãªãã ãã end
メソッド定義ã®ä¸é¨ã§ãããããããæ¸ãæ¹ãã§ããã®ãã¼ã
def foo puts "start" raise "test" puts "end" rescue puts "rescue" ensure puts "ensure" end foo
å®è¡çµæã§ãã
start rescue ensure
ã¯ã©ã¹ãã¢ã¸ã¥ã¼ã«ã®å®ç¾©ã§ã使ãã¾ãã
#ã¯ã©ã¹å®ç¾© class Hoge puts "class start" raise "test" puts "class end" rescue puts "class rescue" ensure puts "class ensure" end #ã¢ã¸ã¥ã¼ã«å®ç¾© module Var puts "module start" raise "test" puts "module end" rescue puts "module rescue" ensure puts "module ensure" end
å®è¡çµæã§ãã
class start class rescue class ensure module start module rescue module ensure