Forum: Ruby-dev super in instance_eval

Posted by ko1 (Koichi Sasada) (Guest)
on 2012-11-26 01:05
(Received via mailing list)
Issue #2402 has been updated by ko1 (Koichi Sasada).

Priority changed from Normal to High

shugo-san
これ,どういう話でしたっけ.
----------------------------------------
Bug #2402: super in instance_eval
https://bugs.ruby-lang.org/issues/2402#change-33897

Author: shugo (Shugo Maeda)
Status: Open
Priority: High
Assignee: ko1 (Koichi Sasada)
Category:
Target version: 2.0.0
ruby -v: ruby 1.9.2dev (2009-11-24 trunk 25909) [i686-linux]


=begin
 instance_evalのブロック内でsuperを呼ぶと、instance_evalで変更された
 selfに対してsuperの呼び出しを行ってしまうようです。

 defiant:build$ cat t.rb
 class Foo
   def foo
     p self
   end
 end

 class Bar < Foo
   def foo
     x = Object.new
     x.instance_eval do
       super
     end
   end
 end

 Bar.new.foo
 defiant:build$ ./ruby-trunk.1124 -v t.rb
 ruby 1.9.2dev (2009-11-24 trunk 25909) [i686-linux]
 #<Object:0x8590f6c>

 Foo#fooが呼ばれるのにselfがObjectという、ちょっとおかしなことになっています。
 ちょっと自信がありませんが、一応パッチを添付します。
=end
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.