Actions
Bug #14611
closedExotic method parameters bug
Bug #14611:
Exotic method parameters bug
Description
Actions
Added by bogdan (Bogdan Gusiev) over 8 years ago. Updated over 8 years ago.
Description
bogdan (Bogdan Gusiev) wrote:
By some reason second parameter is nil when the rest of parameters declared as not used.
Underscore as "not used" here is a convention of Rubocop; your code is no different from:
I would say the bug is that it didn't reject the def in the first place, because of the repeated parameter name.
@phluid61 (Matthew Kerwin) not so fast, ruby allows duplicate "_" as parameters so you can say that you don't want them and ruby should just ignore them
so you don't get a SyntaxError about duplicated argument name like your change did
That has nothing to do with rubocop
Hanmac (Hans Mackowiak) wrote:
@phluid61 (Matthew Kerwin) not so fast, ruby allows duplicate "_" as parameters so you can say that you don't want them and ruby should just ignore them
so you don't get a SyntaxError about duplicated argument name like your change didThat has nothing to do with rubocop
... really? When did that happen? I had a look in syntax.rdoc and other places but didn't see any mention of it.
(edit: turns out this is something I completely missed in the 1.9.3 era)
I did not know that either.
I guess the problem was that bogdan was using variables with
a leading '_'.
With this:
I get in IRB:
SyntaxError ((irb):1: duplicated argument name
With that, however had:
I get no error and the method call works.
I have no idea if this is a bug or a feature but to me,
just from looking at the above, I would have assumed that
_a is equal to _a just as a was (considered) equal to
a above, in "def x(a,a,b)".
Perhaps it is because leading _ underscores are always
assumed to be special. But ideally this should be documented
somewhere nonetheless.
Applied in changeset trunk|r62833.
compile.c: arg var index
_