I'm working on a very simple exercise: a method that can multiply between two and an indefinite number of floats. My first idea for doing this was to use the splat operator:
def multiply a, b, *rest
a * b * rest
end
That was unsuccessful. I then tried this:
def multiply *numbers
total = 1
numbers.each do |x|
total = total * x
end
total
end
The above is almost successful—the problem is that it will accept a single argument, and I want it to require at least two. How can I achieve this?