Actions
Bug #21117
closed
Inconsistent behaviour between "_1" and "it" variables
Description
I believe variables _1
and it
should have consistent behaviour and the same as normal local variables. Here are inconsistencies:
# 1. Assigning new value
[1, 2, 3].each { |v| v = v + 1; p v } # works as expected
[1, 2, 3].each { it = it + 1; p it } # works as expected
[1, 2, 3].each { _1 = _1 + 1; p _1 } # SyntaxError
# 2. Using operators like += on them
[1, 2, 3].each { |v| v += 1; p v } # works as expected
[1, 2, 3].each { it += 1; p it } # SyntaxError but I expected it to work correctly after 1st point
[1, 2, 3].each { _1 += 1; p _1 } # works, which is inconsistent with 1 point
# however, this one does not work
[1, 2, 3].map { _1 += 1 } # runtime error is raised: undefined method '+' for nil (NoMethodError)
If both _1
and it
are advertised as block local variables then I would expect that overwriting works correctly, both using expressions like _1 = _1 + 1
and _1 *= 2
.
Actions
Like0
Like1Like0Like0Like0Like0Like0