From: Kouhei Sutou Date: 2010-01-12T23:00:47+09:00 Subject: [ruby-dev:40059] [Bug:1.8] block.callの中でsuperできない ----Next_Part(Tue_Jan_12_23_00_46_2010_216)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit 須藤です。 r25975の変更 * eval.c (proc_invoke): unbound block created by define_method cannot call super. [ruby-core:26984] から、以下のようにすると NoMethodError: super called outside of method という例外が発生するようになりました。 class Parent def run :parent_run end end class Child < Parent def run callback do super end end def callback(&block) block.call end end Child.new.run # -> 例外 Child#callbackの中のblock.callをyieldにすると例外は起きなく なります。 SubjectにBugをつけてしまったのですが、そもそもこれはBugではな く意図した変更なのでしょうか? とりあえず、テストケースは添付しておきます。 余談ですが、この間リリースされたRuby 1.8.7にもこの変更が入っ ていたため、Rabbitが動かなくなり、この違いに気づきました。 ----Next_Part(Tue_Jan_12_23_00_46_2010_216)-- Content-Type: Text/X-Patch; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="super-in-block-call-raises.diff" Index: test/ruby/test_super.rb =================================================================== --- test/ruby/test_super.rb (revision 26302) +++ test/ruby/test_super.rb (working copy) @@ -149,4 +149,26 @@ c = C.new assert_equal([c, "#{C.to_s}::m"], c.m, bug2419) end + + class Parent + def run + :parent_run + end + end + + class Child < Parent + def run + callback do + super + end + end + + def callback(&block) + block.call + end + end + + def test_super_in_block_call + assert_equal(:parent_run, Child.new.run) + end end ----Next_Part(Tue_Jan_12_23_00_46_2010_216)----