Project

General

Profile

Feature #14758

Updated by grzesiek (Grzegorz Bizon) over 6 years ago

While one of the core principles of Ruby is to extend the language in a way it is a most useful and convenient tool that a software developer can have in their toolbox, lack of a first-class isolation on module level can cause some serious problems problem when project grows beyond some size. 

 This is especially visible in large projects, where most of the code lives in the `lib/` directory, and there are tens or hundreds of modules there. Ideally we would like to make these modules isolated and hide complexity behind facades. Currently it is not possible to isolate such modules, because a developer can still reach beyond boundary of a bounded context, and use `MyModule::InternalClass` directly. 

 It is very difficult to enforce boundaries, currently it requires a lot of work to implement complex static analysis rules. 

 Would it make sense to add support for first-class `package`, `context` or `boundary`, that would be a regular module but would not allow referencing inner constants from outside? 

 ~~~ 
 context MyModule 
   class MyIsolatedClass 
     # ... 
   end 

   def self.build 
     MyIsolatedClass.new 
   end 
 end 

 MyModule::MyIsolatedClass # raises context violation 
 MyModule.build # => Returns an instance of MyModule::MyIsolatedClass 
 ~~~  

 I'm pretty sure that I failed at finding similar feature proposal that has been already submitted, in that case sorry for that! 

 Please let me know what do you think about that! Thanks in advance! <3

Back