Project

General

Profile

Bug #13656

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

~~~ruby ~~~ 
 module Calculations 
   def pluck 
      puts "calculations" 
   end 
 end 

 module Calculations2 
   def pluck 
     puts "calculations2" 
     super 
   end 
 end 

 class Relation 
   include Calculations 
 end 

 Relation.prepend(Calculations2) 

 class CollectionProxy < Relation 
   def pluck 
     puts "collection_proxy" 
     super 
   end 
 end 

 module CollectionProxy2 
   def unrelated 
   end 
 end 

 # this is the critical line 
 CollectionProxy.prepend(CollectionProxy2) 

 ConcreteProxy = Class.new(CollectionProxy) 

 # these are the expected results 
 ConcreteProxy.new.method(:pluck).owner == CollectionProxy 
 ConcreteProxy.new.method(:pluck).super_method.owner == Calculations2 
 ConcreteProxy.new.method(:pluck).super_method.super_method.owner == Calculations 
 ~~~ 

 The critical line is the `CollectionProxy2` CollectionProxy2 module. If I don't prepend it into `CollectionProxy` CollectionProxy (or if I include it instead of prepend it), the expected results pass. But when it *is* prepended, the owner for all `super_method`s super_methods will always be `CollectionProxy`, CollectionProxy, as if it can't find any more ancestors (if you actually call `ConcreteProxy.new.pluck` it does call the three methods, in the correct order). So this is an introspection only problem. 

Back