Project

General

Profile

Bug #7475

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago

=begin 
 A more involved explanation is available at ((<URL:http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/>)) http://erniemiller.org/2012/11/29/ruby-tidbit-include-vs-extend-with-module-class-variables/ 

 In short, the handling of class variables (and constants) when a module is extended vs included is not as expected. 

 Example: 

     module Foo 
       @@foo = 'foo' 
     end 
 
     class Bar 
       include Foo 
     end 

     class Baz 
       extend Foo 
     end 

     Bar.class_variable_get :@@foo # => "foo" 
     Baz.singleton_class.class_variable_get :@@foo # => NameError: uninitialized class variable @@foo in Class 

 We would expect constant and class variable lookup on the singleton class to work, but it doesn't. Both Rubinius and JRuby seem to behave as expected in this case. 

 Thanks! 
 =end 

Back