Issue #19742 has been updated by fxn (Xavier Noria).
Let me clarify the vocabulary as I see it:
And _anonymous_ module has `nil` as name: `anonymous?`
A module may have a _temporary_ name if it was never assigned to a constant that belongs
to a module with a permanent name.
A module may have a _permanent_ name if it was at some point assigned to a constant in a
module with a permanent name.
Please excuse the circularity, but we all know what that means. It is three concepts.
Note that permanent has nothing to do with the name being a working constant path.
Permanent means what it means: there is no way the name is going to change (using public
API). In that sense, I believe the proposal is not aligned with the current way things
work.
Note also that "temporary" and "permanent" are qualities of the name,
not the module.
My personal point of view is that any attempt to introduce "parent" concepts, or
steering into coupling names and constant paths is going to leak. Because in Ruby objects
and storage are decoupled. People used to have types in their language may have
expectations or misconceptions, but those should be revised, Ruby does not have syntax for
types.
----------------------------------------
Feature #19742: Introduce `Module#anonymous?`
https://bugs.ruby-lang.org/issues/19742#change-103638
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
----------------------------------------
As a follow-on <from
https://bugs.ruby-lang.org/issues/19521>gt;, I'd like propose
we introduce `Module#anonymous?`.
In some situations, like logging/formatting, serialisation/deserialization, debugging or
meta-programming, we might like to know if a class is a proper constant or not.
However, this brings about some other issues which might need to be discussed.
After assigning a constant, then removing it, the internal state of Ruby still believes
that the class name is permanent, even thought it's no longer true.
e.g.
```
m = Module.new
m.anonymous? # true
M = m
m.anonyomous # false
Object.send(:remove_const, :M)
M # uninitialized constant M (NameError)
m.anonymous? # false
```
Because RCLASS data structure is not updated after the constant is removed, internally the
state still has a "permanent class name".
I want to use this proposal to discuss this issue and whether there is anything we should
do about such behaviour (or even if it's desirable).
Proposed PR:
https://github.com/ruby/ruby/pull/7966
cc @fxn
--
https://bugs.ruby-lang.org/