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


I'm not against Python (and Node.js) package import approaches, but I think it's a completely separate subject from this ticket, so I'll focus on what I'm requesting for now...

David, I agree with you, and actually, I'd be already happy if "class" created the modules on the fly, but it can't without breaking compatibility, specially because it's not possible to know if the parents would be modules or classes... taking an analogy to "mkdir -p", let me say I'd be happy with something like:

class_p InexistentModule::Inner::MyClass
end

For this new "class_p" constructor, all parent constants should be a module and an error would be raised if any of them happen to exist as a class name. For classes, I'd prefer to do something like:

require 'some_module/inner'
class SomeModule::Inner::InnerClass
end

instead of using class_p...
----------------------------------------
Feature #9064: Add support for packages, like in Java
https://bugs.ruby-lang.org/issues/9064#change-42662

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/