Feature #21155
Updated by artur86 (Artur *) 10 days ago
Given there is a file with a class that needs to be namespaced. There are basically two options currently.
`module` implies indenting the class by one level:
```ruby
module MyNamespace
class MyClass; end
end
```
Scope resolution operator (`::`) needs no indentation, 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
```
Neither options enables to declare a namespace once at the top of a file and let Ruby treat all the subsequent constants to be under that namespace. Wouldn't it be better to implement something similar in Ruby?
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).
[The discussion on StackOverflow](https://stackoverflow.com/q/40809717/2987689).