title: Ruby method returns nil, problem with self reference
body: <p>I have defined a method called ccy which takes in a number <code>num</code>, determines the currency (an attribute of the parent Record model) and returns the number multiplied by a conversion factor. Self, in this case, refers to a Setting, which has a number of attributes of its own and belongs to Record. The method is defined in the Setting model below:</p>
  
  <pre><code>class Setting &lt; ActiveRecord::Base
    belongs_to :record
  
    def ccy(num)
      self.record.currency == "USD" ? ( num * 1 ) :
      self.record.currency == "GBP" ? ( num * 0.616181 ) :
      self.record.currency == "EUR" ? ( num * 0.70618 ) :
      self.record.currency == "CAD" ? ( num * 0.97415 ) : nil
    end
  end
  </code></pre>
  
  <p>This doesn't work, however, because after doing some tests I've discovered that <code>self.record.currency</code> is nil. So, when I try to do something like <code>self.ccy(100)</code> in a rails application, for example, I get the following error:</p>
  
  <pre><code>You have a nil object when you didn't expect it!
  You might have expected an instance of Array.
  The error occurred while evaluating nil.*
  </code></pre>
  
  <p>or this, if I'm doing using some sort of operator on the nil element:</p>
  
  <pre><code>TypeError: nil can't be coerced into Fixnum
  </code></pre>
  
  <p>I've looked around online for a bit and I can't seem to figure out exactly how to fix this. Help appreciated!</p>