Project

General

Profile

Feature #6810

Updated by sawa (Tsuyoshi Sawada) 8 months ago

Is this the expected behavior? To 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 

 A::B.f # => 1 

 A::B::N = 2 

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

 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 

 N = 0 

 A::B.f # => 0 

 A::N = 1 

 A::B.f # => 0 

 A::B::N = 2 

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

Back