Forum: Ruby-dev super in instance_eval

Posted by matz (Yukihiro Matsumoto) (Guest)
on 2013-01-09 09:36
(Received via mailing list)
Issue #2402 has been updated by matz (Yukihiro Matsumoto).


うーん、では、禁止でいいですよ。

Matz.

----------------------------------------
Bug #2402: super in instance_eval
https://bugs.ruby-lang.org/issues/2402#change-35301

Author: shugo (Shugo Maeda)
Status: Assigned
Priority: High
Assignee: matz (Yukihiro Matsumoto)
Category: core
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.