Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skipping extra keyword arguments in Ruby

I defined a method:

def method(one: 1, two: 2)
   [one, two]
end

and when I call it like this:

method one: 'one', three: 'three'

I get:

ArgumentError: unknown keyword: three

I do not want to extract desired keys from a hash one by one or exclude extra keys. Is there way to circumvent this behaviour except defining the method like this:

def method(one: 1, two: 2, **other)
  [one, two, other]
end
like image 452
Nick Roz Avatar asked Jun 19 '15 15:06

Nick Roz


1 Answers

If you don't want to write the other as in **other, you can omit it.

def method(one: 1, two: 2, **)
  [one, two]
end
like image 171
sawa Avatar answered Sep 22 '22 09:09

sawa