Mixing keyword with regular arguments in Ruby?

后端 未结 3 1849
后悔当初
后悔当初 2020-11-27 03:45

Ruby 2.0 supports keyword arguments. I was wondering, what are the \'rules\' for mixing regular with keyword arguments? Something like this would not work:

d         


        
3条回答
  •  猫巷女王i
    2020-11-27 03:55

    1. Arguments with defaults and splat argument must be grouped together;
    2. Splat argument must appear after positional arguments with default values but before keyword arguments;
    3. Keyword arguments must appear after positional arguments and before double splat argument;
    4. Double splat argument must appear last but before block argument.

      def foo(a, b=1, c=2, *d, e, f: 1, g: 2, **kwargs, &block)

提交回复
热议问题