-1

I have the following code that as far as I know should work correctly but doesn't:

def calculate( *nums, options = {} ) //errors out here on equals sign
  if options.empty
    return add(nums)
  elsif options[:subtract]
    return substract(nums)
  elsif options[:add]
    return add(nums)
  end
end

Error:

class: SyntaxError message: /opt/eval-server/eval-server/app/models/eval_spec_runner.rb:5: syntax error, unexpected '=', expecting ')' def calculate( *nums, options = {} ) ^ backtrace: RubyMonk:18:in `eval'

Community
  • 1
  • 1
jStaff
  • 650
  • 1
  • 9
  • 25
  • I am pretty sure no one can explain this better than @JörgWMittag did on [This SO Post](http://stackoverflow.com/a/17173107/1978251). BTW you could not define options in the signature and instead use something like `options = nums.last.is_a?(Hash) ? nums.pop : {}` in the body of your method. – engineersmnky Feb 08 '17 at 21:14
  • That post solves this one. I cannot delete this post because it is flagged by a moderator. – jStaff Feb 09 '17 at 21:26

1 Answers1

1

A splat argument must be the last argument of your method.

Brennan
  • 5,632
  • 2
  • 17
  • 24