so I'm working through some examples of Ruby Methods from the rubymonk website and am having trouble interpreting what is going on in the code below. More specifically, I was hoping that someone might be able to help explain in layman's terms what each line in the code from the 'calculate' method is describing? I really appreciate any and all help!
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)
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