title: Rails associated models with a method of the same name
body: <p>I'm working with a massive legacy code base, so I am looking for advice concerning this particular issue, please, not suggestions of better high-level implementations.</p>
  
  <p>A simplified version of what I'm working with:</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
     has_many :line_items
     #other stuff
  
     def balance
         #some definition
     end
  end
  
  class LineItem &lt; ActiveRecord::Base
     belongs_to :order
     #other stuff
  end
  
  module Concerns
    module LineItems
      module Aggregates
        extend ActiveSupport::Concern
        #stuff
  
        def balance
            #some other definition
        end
  
      end
     end
  end
  </code></pre>
  
  <p>Order has a method called 'balance,' and a module of LineItem also has a method called 'balance.' It seems that most of the time (in most places in the code base), when specific_line_item.balance is called, it used the method definition under the LineItem module, but there are a couple of places where it instead calls the method from Order. </p>
  
  <p>Is there any way in Ruby/Rails to specify on method call which of these two I'd like to use? OR is there probably something else going on here because Ruby doesn't have method overloading, so the problem I'm describing here isn't possible?</p>
  
  <p>All relevant cases where either method is called are coming from a line_item (i.e. specific_line_item.balance), so I would think it would always choose the method closer to home, rather than making the associative jump and calling Order's 'balance' method without being told to. </p>
  
  <p><strong>EDIT:</strong>
  Thanks for the responses! It seems I wasn't clear enough with my question. I understand the difference between</p>
  
  <pre><code>Order.first.balance
  </code></pre>
  
  <p>and</p>
  
  <pre><code>LineItem.first.balance
  </code></pre>
  
  <p>and that the balance method being called is the one defined within the class for that object. In the situation I'm describing, I observed, in the actual live app environment, that at a place in the code where </p>
  
  <pre><code>LineItem.find(some_id).balance
  </code></pre>
  
  <p>was called it output not the result that would be computed by the LineItem 'balance' method, but the one from the Order class.</p>
  
  <p>So I had hoped to learn that there's some ruby quirk that might have an object call an associate's method of the same name under some conditions, rather than it's own. But I'm thinking that's not possible, so there's probably something else going on under the covers specific to this situation.</p>