Forum: Ruby-core super: no superclass method in Ruby 2.1.1

Cb4694dbddc0b972c5e530a4104b6edb?d=identicon&s=25 unknown (Guest)
on 2014-04-14 06:01
(Received via mailing list)
Issue #9721 has been updated by Wei Hu.


Hi, Nakada,
Thanks for your fix, but this still have problem. If we run my original
example, it will result into:
~~~
B
B
B
t.rb:9: stack level too deep (SystemStackError)
~~~

I think the difference is: in the original example, I used
~~define_method :foo~~~ to override the foo in Module B.



----------------------------------------
Bug #9721: super: no superclass method in Ruby 2.1.1
https://bugs.ruby-lang.org/issues/9721#change-46204

* Author: Wei Hu
* Status: Closed
* Priority: Normal
* Assignee:
* Category: core
* Target version: current: 2.2.0
* ruby -v: ruby 2.1.1p76 (2014-02-24 revision 45161) [x86_64-linux]
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED
----------------------------------------
Below code will result into error:

~~~
super: no superclass method `foo' for #<Object:0x002b0430670fe8>
~~~

However, it can pass with Ruby 1.9 and I am not sure if it's feature
changes or bug.

~~~ruby
module A
  def foo
    puts "A"
  end
end

module B
  def foo
    puts "B"
    super
  end
  ub_meth = instance_method :foo
  define_method :foo do
    ub_meth.bind(self).call()
  end
end
a = Object.new
a.extend A
a.extend B
a.foo
~~~
This topic is locked and can not be replied to.