Issue #19742 has been updated by fxn (Xavier Noria).
There is no semantics for anonymous? because it does
not exist in Ruby yet.
I used the word "semantics" because the docs use the English word
"anonymous", which is not formal, but would be surprising that `anonymous?` does
not behave like like what "anonymous" says today.
The problem is, in your logic, it's "if"
not "iff".
Yes, but the other direction is "if the name is `nil`, then the module is
anonymous". But this is not what we are discussing right? We are discussing if an
anonymous module can have a name that is not `nil`. To see that is not possible, you need
the arrow in the docs.
I think conceptually, a name is set needs to be
clarified - do you mean a permanent name or a non-permanent name? I wonder if we should
change name to return nil if set_temporary_name is used to avoid this confusion.
I personally believe it is fine, even expected, that `name` returns the temporary name.
Because that is what it does when implicitly set by Ruby today, and because, well, it is
the name at this point in time. It may change, variable vs constant.
Hey let me say explicitly that I am participating in the discussion to contribute to it,
but Ruby core are who define how the language evolves. So, given we come from different
angles that won't reconcile, whatever core decides is going to be OK for me :).
----------------------------------------
Feature #19742: Introduce `Module#anonymous?`
https://bugs.ruby-lang.org/issues/19742#change-103656
* 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/