
Issue #19450 has been updated by ioquatix (Samuel Williams). Here are some of the places in my own code I'd like to use such a feature: - https://github.com/ioquatix/bake/blob/a571f0c47cc202a4b46a836b87b7383d84f74f... - "Scope<path/to/file.rb>" - https://github.com/ioquatix/bake/blob/a571f0c47cc202a4b46a836b87b7383d84f74f... - "<Path/To/File>" probably makes sense. - https://github.com/socketry/utopia/blob/7f24d503f46000076fbdeeb6e28e293c9544... - probably "Controller<relative/uri/path>" - https://github.com/ioquatix/sus/blob/65e408bad260d168701bad79b2cb905ef65435e... - probably "Base<description>" - https://github.com/ioquatix/sus/blob/65e408bad260d168701bad79b2cb905ef65435e... - probably "It<path/to/file.rb:line>" There are other systems that would benefit from this, e.g. RSpec, or any test framework which loads tests into anonymous modules, or any system that basically creates `Module.new`/`Class.new` and subsequently loads code from one or more files into them.
But it doesn't affect Module#name and error messages, which IMO is good, so error messages don't lie about this.
I disagree, the anonymous `#<#<Class:0x00007fd0ad4b3860>::Bar:0x00007fd0ad81ec70>` names are near useless. Where did it come from? Where was it defined?
Related, Marshal and other places use rb_mod_name() (or similar) to find the class name.
In my PR, it's still considered an anonymous class. So it can't be marshalled.
One requirement for that is the given name should not be a valid constant name then (not start with a uppercase letter).
That's not how it works internally, there is actually a flag for anonymous/permanent name. ---------------------------------------- Feature #19450: Is there an official way to set a class name without setting a constant? https://bugs.ruby-lang.org/issues/19450#change-102050 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal ---------------------------------------- This is the best I could come up with: ```ruby klass = Class.new Object.const_set("Klass", klass) Object.send(:remove_const, "Klass") puts klass.new # => #<Klass:0x0000000100a9d688> ``` Can we do better? What about something like: ```ruby Class.new(name: "Klass") ``` or ```ruby Class.new do def self.name "Klass" end end ``` etc -- https://bugs.ruby-lang.org/