
Issue #19450 has been updated by jeremyevans0 (Jeremy Evans). matheusrich (Matheus Richard) wrote in #note-9:
Semi-related (maybe it should be a separate issue?) but assigning a class to a constant via rightward assignment results in `NameError`
``` ruby Class.new => Klass # uninitialized constant Klass (NameError) ```
Not a bug. "Rightward assignment" is not assignment, but pattern matching: ```ruby 1 => Bar # raises NameError, because Bar is not defined 1 => Integer # nil 1 => String # NoMatchingPatternError, because String === 1 is not true ``` ---------------------------------------- Feature #19450: Is there an official way to set a class name without setting a constant? https://bugs.ruby-lang.org/issues/19450#change-102024 * 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/