From: Hideto ISHIBASHI Date: 2000-04-22T19:49:50+09:00 Subject: [ruby-list:22066] Re: assert ----Next_Part(Sat_Apr_22_19:38:56_2000_678)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit 石橋秀仁です。 > 友谷です。 > で、assertを組み込むのであればこんなのはどうでしょうか。 ちょっと脱線します。 厳密にはassertではないのですが、次のようなものはどうでしょう? 実行時にエラーの回復をするためのライブラリです。 -- Hideto "rubyholic" ISHIBASHI ----Next_Part(Sat_Apr_22_19:38:56_2000_678)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=assert.rb module Assert class AssertionError < StandardError; end def assert(*args, &block) return nil unless $DEBUG __assert__(*args, &block) end def __assert__(*args) return true if yield == true msg = "assertion failed:" for arg in args msg += " " + arg.inspect end raise AssertionError, msg end def recoverable_assert(*args, &block) return nil unless $DEBUG assert_and_recovery(*args, &block) end def assert_and_recovery(*args, &block) begin return true if __assert__(*args, &block) rescue exception = $! STDOUT.print exception, "\n" for c in caller(0) STDOUT.print c, "\n" end end STDOUT.print "type 'help' to display help message.\n" loop do input = readline("(recovery:-) ") case input when /^\s*h(?:elp)?\s*$/ STDOUT.print <