Project

General

Profile

Feature #21155

Updated by artur86 (Artur *) 10 days ago

Given there is a class that needs to be namespaced. There are basically two options. 

  

 `module` requires indenting the class by one level: 

 ```ruby 
 module MyNamespace 
   class MyClass; end 
 end 
 ``` 

 Scope resolution operator (`::`) does not require it, but it works differently than using `module` and repeating module name for every class inside seems tedious and verbose to me: 
 ```ruby 

 class MyNamespace::MyClass; end 
 class MyNamespace::MyAnotherClass; end 
 class MyNamespace::OneMoreClass; end 
 end 
 ``` 

 Wouldn't it be better What if something similar to be able to say `module MyNamespace` at the top of the file once and expect Ruby to treat all constants [File Scoped Namespaces in that file to C#](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces) would be under that namespace? 

 This is implemented in C# under the name of [File Scoped Namespaces](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces). Ruby? 

 The concept is very clearly formulated in [a question on StackOverflow](https://stackoverflow.com/q/40809717/2987689) and sounds like "everything in this file should be in some module".

Back