From: Yusuke Endoh Date: 2011-12-26T23:28:36+09:00 Subject: [ruby-core:41814] Re: [ruby-trunk - Feature #5474][Assigned] keyword argument Hello, Marc-Andre 2011/12/22, Marc-Andre Lafortune : > While having fun testing your patch, I encountered an issue with more > than 2 rest arguments: > > def foo(*rest, b: 0, **options) > [rest, options] > end > > foo(1, 2, bar: 0) # => [[1, 2], {bar: 0}] OK > foo(1, 2, 3, bar: 0) # => [[1, 2, {bar: 0}], {bar: 0}] Not OK Good catch! The commits I've done now include a fix for this. > On 30 October 2011 11:10, Yusuke Endoh wrote: >> Currently, my patch allows ** only when there are one or more >> keyword arguments. >> >> This is because I didn't think of any use case. >> In addition, I wanted to simplify the implementation of parser. >> (Unfortunately, adding a new argument type requries *doubling* >> the parser rules to avoid yacc's conflict) >> Do you think we need it? > > I'm worried about cases where one doesn't use named arguments directly > but wants to pass them on to another method. Indeed. I've missed delegate. >> I didn't implement caller's **. >> I wonder if we need it or not. Is "other(a, h)" not enough? > > I think one reason to have it is to avoid calling Hash#merge when > combining options, like in the above examples. > > Instead of > > def foo(bar: 42, **options) > baz(extra_option: 1, **options) > end > > Currently, one has to do: > > def foo(bar: 42, **options) > baz(options.merge(extra_option: 1)) > end Oh yeah, I understand the use case. I'll work for these two, after matz shows his opinion for your new alternative syntax. Thanks! -- Yusuke Endoh