title: Access subclass constants after inheritance
body: <p>I have a model in my Rails application with a number of constants defined on it:</p>
  
  <pre><code>class Product &lt; ApplicationRecord
    ALIASES = {
      places: :geographic_places,
      prices: :product_prices,
      productPrices: :product_prices,
      productSpecification: :product_spec
    }
  
    ALIASES.each do |k, v|
      alias_attribute k, v
    end
  
    ATTRIBUTES = [:name, :description, :isBundle, :lastUpdate, :validFor]
    ASSOCIATIONS = [:productPrice, :productSpecification, :place]
  
    # The rest of the class has been omitted for brevity
  end
  </code></pre>
  
  <p>My ALIASES are in a hash so I can later lookup which association I am following given an alias. You can see that I set each alias up as an <code>alias_attribute</code>.</p>
  
  <p>However this snippet will be repeated in all of my models:</p>
  
  <pre><code>ALIASES.each do |k, v|
    alias_attribute k, v
  end
  </code></pre>
  
  <p>I would like the base class, ApplicationRecord, to be able to handle that for me. I have a similar requirement for some methods in the ApplicationRecord to be aware of ATTRIBUTES and ASSOCIATIONS. However I can't find a way to access inheriting-class's constants. </p>
  
  <pre><code>class ApplicationRecord &lt; ActiveRecord::Base
    self.abstract_class = true
  
    # 1
    base_class::ALIASES.each { |k, v| alias_attribute k, v } # =&gt; NameError: Uninitialized constant ApplicationRecord::ALIASES
  
  
    def class &lt;&lt; self
      # 2
      base_class::ALIASES.each { |k, v| alias_attribute k, v } # =&gt; NameError: Uninitialized constant ApplicationRecord::ALIASES
  
      # 3 - inherited fires BEFORE the subclass code is run
      def inherited(subclass)
        puts subclass.name # =&gt; Product
        subclass.const_get(:ALIASES) # =&gt; NameError: uninitialized constant Product::ALIASES
      end
  
      # By the way, this works
      def table_name
        self.base_class.name.underscore + '_records'
      end
      # Elsewhere: Product.table_name # =&gt; 'product_records'
    end
  end
  </code></pre>
  
  <p>How can I access the inheriting class's constants after they are initialized?</p>
  
  <p>(Ruby 2.4.1, Rails 5.1.5)</p>