title: What does RubyMonk's calculate method do?
body: <p>I'm learning Ruby on RubyMonk right now and am struggling with the code below: the <code>calculate</code> method -> <code>def calculate(*arguments)</code>. Is it possible that you can explain to me each line of code? I think I know what each code line's syntax, but the logic doesn't make any sense to me?</p>
  
  <pre><code>def add(*numbers)
      numbers.inject(0) { |sum, number| sum + number }  
  end
  
  def subtract(*numbers)
    sum = numbers.shift
    numbers.inject(sum) { |sum, number| sum - number }  
  end
  
  def calculate(*arguments)
    # if the last argument is a Hash, extract it 
    # otherwise create an empty Hash
    options = arguments[-1].is_a?(Hash) ? arguments.pop : {}
    options[:add] = true if options.empty?
    return add(*arguments) if options[:add]
    return subtract(*arguments) if options[:subtract]
  end
  </code></pre>
  
  <p>for example, the <code>options</code> is killing me...I don't know what result returns from the two lines...</p>
  
  <p>Thank you so much!</p>