Project

General

Profile

Feature #6810

Updated by sawa (Tsuyoshi Sawada) almost 5 years ago

=begin 
 Is this the expected behavior?    To me, me it is rather surprising: 

 ```ruby 
 

  N = 0 

 

  module A 
   
    module B 
     
      def self.f; N; end 
   
    end 
   
    N = 1 
 
  end 

 

  A::B.f # => 1 
 ``` 


 

 but 

 ```ruby 
 

  N = 0 

 

  module A; end 

 

  module A::B 
   
    def self.f; N; end 
 
  end 

 

  module A 
   
    N = 1 
 
  end 

 

  A::B.f # => 0 
 ``` 

 Even more striking: 

 ```ruby 
 

  module A 
   
    module B 
     
      def self.f; N; end 
   
    end 
 
  end 

 

  N = 0 

 

  A::B.f # => 0 

 

  A::N = 1 

 

  puts A::B.f # => 1 

 

  A::B::N = 2 

 

  A::B.f # => 2 
 ``` 

 but 

 ```ruby 
 

  module A; end 

 

  module A::B 
   
    def self.f; N; end 
 
  end 

 

  N = 0 

 

  A::B.f # => 0 

 

  A::N = 1 

 

  A::B.f # => 0 

 

  A::B::N = 2 

 

  A::B.f # => 2 
 ``` 
 


 =end

Back