From: matz@... (Yukihiro Matsumoto) Date: 2003-11-19T21:10:33+09:00 Subject: Re: Again, Rite explanation needed (keyword args and new hash syntax) Hi, In message "Re: Again, Rite explanation needed (keyword args and new hash syntax)" on 03/11/19, Greg McIntyre writes: |I'm a bit confused by this too. | |--- |def f(a, b: 2, **kwd) | p [a,b,kwd] |end | |f(1) #=> [1,2,{}] |f(1,b:5) #=>[1,5,{}] |f(1,b:5,c:6) #=>[1,5,{:c=>6}] | |--- | |Is the double asterisk (**) especially for grouping the rest of the |arguments into a hash the same way that a single asterisk groups the |rest of the arguments into an array? If so, Basic Rule: Double asterisk for grouping the rest of keyword arguments. Keyword arguments don't mix positional arguments (including optional ones). | f(1,b:5,6,7,8) # => ? runtime error? Syntax Error. Every keyword argument come after positional arguments. |Can I still use position to in the argument list and forgo the |keywordiness? | | f(1,5) # => [1,5,{}] Argument Error. f() requires single positional argument, you specified two. |Can I change the order of the arguments or leave as many as I like out? |Shouldn't that be included in the primary example of this? It is the |point, isn't it? | | def g(a:1,b:2,c:3) | [a,b,c] | end | | g(c:5,b:6) # => [1, 6, 5] Yes. Order doesn't matter for keyword arguments. matz.