From: "Eregon (Benoit Daloze) via ruby-core" Date: 2023-02-20T14:52:48+00:00 Subject: [ruby-core:112509] [Ruby master Feature#19450] Is there an official way to set a class name without setting a constant? Issue #19450 has been updated by Eregon (Benoit Daloze). I don't think Class#inspect should ever lie, so IMO there shouldn't be a way. In the comment above, the problem is `foo` is not assigned to a proper constant, that's the obvious fix, to assign foo to a constant. The file in which the class is defined is another feature, maybe we should add `Module#source_location` (TruffleRuby already tracks that for interop). ---------------------------------------- Feature #19450: Is there an official way to set a class name without setting a constant? https://bugs.ruby-lang.org/issues/19450#change-101954 * 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 # => # ``` 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/