Bug #8418

when all params are optional, named arg hash maps to the first available param

Added by First Last over 2 years ago. Updated almost 2 years ago.

ruby -v:ruby 2.0.0p195 (2013-05-14 revision 40734) [i686-linux] Backport:1.9.3: UNKNOWN, 2.0.0: UNKNOWN


irb(main):028:0> def foo(arg = 1, options = {}); {arg: arg, options: options}; end; foo(a: 1)
=> {:arg=>{:a=>1}, :options=>{}}

since positional args can't follow the named hash, perhaps the named hash should map to the last possible param?


#1 Updated by First Last over 2 years ago

that would also make it correspond to the new syntax

irb(main):034:0> def foo(arg = 1, **options); {arg: arg, options: options}; end; foo(a: 1)
=> {:arg=>1, :options=>{:a=>1}}

#2 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Open to Rejected

That's the reason that keyword argument is introduced.

#3 Updated by First Last almost 2 years ago

but isn't it good to have correspondence between keyword args and keyword hash?

when keyword args are used explicitly at invocation (foo a: 1, foo **hash) but the method signature does not use keyword params, it seems natural to bind the resulting hash to the last possible param, not the first

Also available in: Atom PDF