Project

General

Profile

Bug #8297

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

=begin 
 By the current documentation, (({Object#extend})) Object#extend method has to (only) add instance methods of a module given as a parameter. 
 In the following example, the class ((|C|)) ((*C*)) is extended with module ((|M|)). ((*M*)). 
 By (({class_variables})) ((*class_variables*)) method sent to singleton class of C also did inherit class variable ((|@@xyz|)). ((*@@xyz*)). 
 However when inherited ((|@@xyz|)) ((*@@xyz*)) is accessed, (({NameError})) ((*NameError*)) exception is raised as it is was not initialized. 

   module 

 (({module M 
     
       @@xyz = 123 
   
 end 
   
 M.class_variables      # [:@@xyz] 
   
 M.class_variable_get :@@xyz      # 123 , so far so good 

   

 class C 
     
       extend M 
   
 end 
   p 
 ((*p C.singleton_class.class_variables      # [:@@xyz] 
   
 p C.singleton_class.class_variable_get :@@xyz # NameError exception exception*)) 
 })) 

 Either (({class_variables})) ((*class_variables*)) returns invalid array - ie. ((|@@xyz|)) ((*@@xyz*)) was not inherited at all or (({class_variable_get})) ((*class_variable_get*)) ignores class variables inherited from module (when sent to a singleton). 
 =end 
 Prior Ruby versions like 1.9.3p392 does not suffer this issue as return with Module#class_variables returns an empty array. 

Back