From: "boris_stitnicky (Boris Stitnicky)" Date: 2012-10-15T13:47:59+09:00 Subject: [ruby-core:47995] [ruby-trunk - Feature #7149] Constant magic for everyone. Issue #7149 has been updated by boris_stitnicky (Boris Stitnicky). Not out of the box, only if the user turns it on: class Fixnum constant_magic # or constant_magic( true ); or const_magic(); etc. end But, oh, do I feel your point. Saying that naming 42 is stupid is not enough. Giving objects - any objects, not just fringe cases like Numerics, Symbols, Vectors etc. - wrong names is a sin, root of evil surrounding the true nature :) They say the devil himself is perhaps skin alone. I revulse names, unless these be good hash functions, like those of Tolkien's Ents. But alas, biologists deserve not the name of their science: they indulge in dissecting and giving names that obscure rather than identify. Should this be remedied at the language level? Definitely. But there is no way we would see this done before the end of the century, if at all. So, sadly, I have to live in the world I find myself in, refrain from proposing to prohibit constants altogether, and satisfy myself with proposals that seem to even foster the evil of deficient synonyms. Going back to naming 42, please note that the rope to hang oneself with is already there: This behavior is achievable with present devices of Ruby. I am only begging to make the possible more efficient. Searching whole namespace gives me goosebumps. ---------------------------------------- Feature #7149: Constant magic for everyone. https://bugs.ruby-lang.org/issues/7149#change-30704 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/