1
    def a(b: 88, c: 97)
      puts b
      puts c
    end

The above code works. But,

def a(b: 88, c: 97, *c)
  puts b
  puts c
end

Throws a syntax error. Can anyone point me to the right documentation that explains it?

Pramodh KP
  • 199
  • 5
  • What is your code supposed to do, i.e. what is the expected value for `c` within the method when being called with different values? – Stefan Nov 17 '16 at 11:15

1 Answers1

5

Positional arguments go first in a method signature. Named arguments go last.

This will work better, but you still have a duplicate parameter name, which is not allowed.

def a(*c, b: 88, c: 97)
  puts b
  puts c
end
# ~> -:1: duplicated argument name
# ~> def a(*c, b: 88, c: 97)
# ~>                    ^

Great answers with more info: Mixing keyword with regular arguments in Ruby?

Community
  • 1
  • 1
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367