From 1ea4c512450a79e979b2652764b35a28630f5570 Mon Sep 17 00:00:00 2001 From: KOBAYASHI Shuji Date: Sat, 6 Feb 2021 13:28:47 +0900 Subject: Make the argument of `Kernel#catch` optional as Ruby does Also implement the following changes. * Add tests * Use `Object#equal?` to compare tags for Ruby compatibility * Use `attr_reader` --- mrbgems/mruby-catch/mrblib/catch.rb | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'mrbgems/mruby-catch/mrblib') diff --git a/mrbgems/mruby-catch/mrblib/catch.rb b/mrbgems/mruby-catch/mrblib/catch.rb index f8dcb3e84..68b165c8d 100644 --- a/mrbgems/mruby-catch/mrblib/catch.rb +++ b/mrbgems/mruby-catch/mrblib/catch.rb @@ -1,22 +1,17 @@ class ThrowCatchJump < Exception + attr_reader :_tag, :_val def initialize(tag, val) - @tag = tag - @val = val + @_tag = tag + @_val = val super("uncaught throw #{tag.inspect}") end - def _tag - @tag - end - def _val - @val - end end module Kernel - def catch(tag, &block) + def catch(tag=Object.new, &block) block.call(tag) rescue ThrowCatchJump => e - unless e._tag == tag + unless e._tag.equal?(tag) raise e end return e._val -- cgit v1.2.3