Skip to content
  • Jean Boussier's avatar
    a6621912
    alias_attribute: handle user defined source methods · a6621912
    Jean Boussier authored
    `alias_attribute` used to define a "jump method", e.g.
    `alias_attribute :foo, :bar` was pretty much a macro to generate
    
    ```ruby
    def foo
      bar
    end
    ```
    
    This is convienient because it's easy, it doesn't impose an order
    of declaration or anything like that.
    
    But it's also much less efficient than a true `alias_method`.
    
    It also used to cause cache size explosion which we fixed in
    https://github.com/rails/rails/pull/52118, but making it behave
    like Ruby's `alias_method`, by doing a real alias.
    
    But this breaks some expectations (literally from the documentation):
    
    ```ruby
      attr_accessor :name
      attribute_method_suffix '_short?'
      define_attribute_methods :name
    
      alias_attribute :nickname, :name
    ```
    
    Here we're not supposed to alias a generated method, but a user defined one.
    
    So this assumption can only hold for Active Record, not Active Model.
    a6621912
    alias_attribute: handle user defined source methods
    Jean Boussier authored
    `alias_attribute` used to define a "jump method", e.g.
    `alias_attribute :foo, :bar` was pretty much a macro to generate
    
    ```ruby
    def foo
      bar
    end
    ```
    
    This is convienient because it's easy, it doesn't impose an order
    of declaration or anything like that.
    
    But it's also much less efficient than a true `alias_method`.
    
    It also used to cause cache size explosion which we fixed in
    https://github.com/rails/rails/pull/52118, but making it behave
    like Ruby's `alias_method`, by doing a real alias.
    
    But this breaks some expectations (literally from the documentation):
    
    ```ruby
      attr_accessor :name
      attribute_method_suffix '_short?'
      define_attribute_methods :name
    
      alias_attribute :nickname, :name
    ```
    
    Here we're not supposed to alias a generated method, but a user defined one.
    
    So this assumption can only hold for Active Record, not Active Model.
Loading