title: Multiplication in Ruby on Rails Model of nil values
body: <p>I have several calculated values as part of my risk.rb model</p>
  
  <pre><code>before_save :calculate_risk
  def calculate_risk
    self.risk1_total = self.component1 * self.component2 * self.component3
    self.risk2_total = self.component4 * self.component5 * self.component6
    ...
  end
  </code></pre>
  
  <p>I want to be able to create a risk without filling out the form completely thus each of those components would be nil. So this method creates an error because * is not a valid method for a nil. What is the best way to handle this? I have considered</p>
  
  <pre><code>def calculate_risk
    if self.component1.nil? || self.component2.nil? || self.component3.nil?
      self.risk1_total = self.component1 * self.component 2 * self.component3
    elsif ...
  end
  </code></pre>
  
  <p>However, this is obviously inefficient and repetitive. I also considered initializing all of these values, though I do not know the most efficient way of doing this. </p>