From: "prijutme4ty (Ilya Vorontsov)" Date: 2012-10-14T17:11:20+09:00 Subject: [ruby-core:47972] [ruby-trunk - Feature #7149] Constant magic for everyone. Issue #7149 has been updated by prijutme4ty (Ilya Vorontsov). May be any hook can be implemented to make it possible in such a way? on_const_set do{|const, obj| def obj.name const end } ---------------------------------------- Feature #7149: Constant magic for everyone. https://bugs.ruby-lang.org/issues/7149#change-30616 Author: boris_stitnicky (Boris Stitnicky) Status: Feedback Priority: Normal Assignee: Category: Target version: I noticed that certain objects have constant magic: When they are first assigned to a constant, they acquire a name property equal to the constant name string. I only know about Class and Struct objects behaving this way. I like this behavior, because I like to be able to say something like: Adenosine = ChemicalSpecies.new initial_concentration: 5.micromolar Adenosine.name #=> "Adenosine" I like it so much, that I wrote a library (I call it ConstantMagicErsatz) for myself that searches whole namespace for the new objects assigned to constants. But searching whole wild namespace has its pitfalls. It is a wildly difficult workaround to get the candy I want. I am dreaming about just being able to say: class ChemicalSpecies constant_magic true end and imbue ChemicalSpecies with the same constant magic ability that Class and Struct classes have. Could it be made possible, please? -- http://bugs.ruby-lang.org/