Feature #13979
closedRuby doesn't give error on keyword arguments that you can't refer to
Description
You can't use keywords as names for normal arguments. For example all of these give a syntax error:
The reason is that there's no way to refer to these names because they are keywords.
However, we can use these names for keyword arguments. All of these work:
But I think they should give a syntax error, because for example I can't refer to the argument "class" in the first line (same reason why the first snippet gives a syntax error).
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
- Description updated (diff)
- Status changed from Open to Rejected
Use Binding#local_variable_get.
Updated by Eregon (Benoit Daloze) over 8 years ago
@nobu (Nobuyoshi Nakada) Is there any value to support such keyword arguments?
I think an early error might be less surprising here.
On the callee side, I think it's a lot more practical to use **keyrest in such a case like keyrest.fetch(:class, 1).
Updated by asterite (Ary Borenszweig) over 8 years ago
Thank you nobu, I didn't know about Binding#local_variable_get
Updated by nobu (Nobuyoshi Nakada) over 8 years ago
Eregon (Benoit Daloze) wrote:
@nobu (Nobuyoshi Nakada) Is there any value to support such keyword arguments?
I think an early error might be less surprising here.
I've heard the example that Rails (maybe ActiveSupport?) had used if: as short for "interface".
Binding#local_variable_get does not encourage to use such arguments.
Updated by ko1 (Koichi Sasada) over 8 years ago
Binding#local_variable_getdoes not encourage to use such arguments.
But Binding#local_variable_get is introduced for this purpose :p