
Issue #19520 has been updated by fxn (Xavier Noria). This is a long thread, I was not aware of it. Let me say that nobody can assume from the name of a class or module that the corresponding constant exists. Class and module objects get their name when they are first assigned to a constant, and the `class` and `module` keywords are in part constant assignments. We all know this. We also know the coupling ends there. These entities ar highly decoupled in Ruby by design. I can have `C = Class.new; c = C; remove_const :C`, and the class in `c` is no longer reachable through the constant after its name. If a Ruby programmer expects that, they have to revise that expectaction because it is just baseless. ---------------------------------------- Feature #19520: Support for `Module.new(name)` and `Class.new(superclass, name)`. https://bugs.ruby-lang.org/issues/19520#change-102426 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- See <https://bugs.ruby-lang.org/issues/19450> for previous discussion and motivation. [This proposal](https://github.com/ruby/ruby/pull/7376) introduces the `name` parameter to `Class.new` and `Module.new`: ```ruby Class.new(superclass, name) Module.new(name) ``` As a slight change, we could use keyword arguments instead. ## Example usage The current Ruby test suite has code which shows the usefulness of this new method: ```ruby def labeled_module(name, &block) Module.new do singleton_class.class_eval { define_method(:to_s) {name} alias inspect to_s alias name to_s } class_eval(&block) if block end end module_function :labeled_module def labeled_class(name, superclass = Object, &block) Class.new(superclass) do singleton_class.class_eval { define_method(:to_s) {name} alias inspect to_s alias name to_s } class_eval(&block) if block end end module_function :labeled_class ``` The updated code would look like this: ```ruby def labeled_module(name, &block) Module.new(name, &block) end def labeled_class(name, superclass = Object, &block) Class.new(superclass, name, &block) end module_function :labeled_class ``` -- https://bugs.ruby-lang.org/