Issue #9064 has been updated by rosenfeld (Rodrigo Rosenfeld Rosas).


david_macmahon (David MacMahon) wrote:

>...  If we change the behavior, then the implicit creation of module MyModule and module MyModule::MyClass and module MyModule::MyClass::InnerModule will "work", but then any subsequent attempt to create class MyModule::MyClass will fail loudly...

What I was trying to say is that MyClass will be a different object depending on the order you require 'my_module/my_class/inner_module' unless this file explicitly requires 'my_module/my_class' before defining InnerModule. If this is not the case, you would get no error in your application if it first requires MyClass and then InnerModule. But if for some reason inner_module is loaded first at some point, things will break later when you require MyClass. Currently it will break as soon as you require InnerModule without requiring MyClass first...

I'm particularly not worried about this behavior since I always opt for explicit in my applications and it doesn't matter at all the order in which my files are required since they would always behave the same way. But since this is not a common practice in the Ruby community I think the Ruby core team might be worried about this behavior change...
----------------------------------------
Feature #9064: Add support for packages, like in Java
https://bugs.ruby-lang.org/issues/9064#change-42689

Author: rosenfeld (Rodrigo Rosenfeld Rosas)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: 


In Java, it's easy to define a package for a certain class:

package com.company.MyClass

We don't use that convention in Ruby but we have another way of packaging classes:

module MyLibrary
  module InnerNamespace
    class MyClass
    end
  end
end

I'd prefer to be able to use something like this instead meaning exactly the same thing:

package MyLibrary::InnerNamespace # or MyLibrary.InnerNamespace, I don't really care
class MyClass
end

Could you please consider this idea?


-- 
http://bugs.ruby-lang.org/