super call may use wrong receiver object
The code below prints:
which means that the super calls the instance method B#m on a receiver that is not an instance of B. It's not what makes the super call to pick the main object as a receiver in this case. I would expect it to use the "self" object that the block captures, i.e. the class object C, and thus an exception "no superclass method `m' (NoMethodError)" should be raised.
puts self.class.to_s + '::m'
class C < B
q = Proc.new do
mq = define_method :m, &q
BTW: The behavior is even worse in Ruby 1.9:
ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]
==': wrong number of arguments(0 for 1) (ArgumentError)block in class:C'
from a.rb:8:in `'
Updated by ujihisa (Tatsuhiro Ujihisa) over 10 years ago
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
FYI: In my environment, the latter result was different.
ruby 1.9.2dev (2009-11-30 trunk 25961) [i386-darwin9.8.0]
block in <class:C>': super: no superclass methodremove_const' for C:Class (NoMethodError)
from /var/folders/Dz/Dz5WpFSZGUaFLA8jp8kT5E+++TM/-Tmp-/v408625/85:9:in `'
(Please ignore the difference of line numbers)