Actions
Bug #19583
closedUnary minus inconsistency when used with variables and literals
Description
This feels a bit inconsistent and I could not find an explanation.
This is fine and -
has higher precedence than .
-2.upto 0 do |arg|
puts arg
end
But this is not working, won't even compile (requires parens):
var = 2
-var.upto 0 do |arg|
puts arg
end
I presume that in the first example there is no unary minus operation, just negative literal.
Ok, according to this - my assumption is correct. The question is - why?
def some
puts -2
a = 42
puts -a
end
puts RubyVM::InstructionSequence.of(method :some).disasm
Actions
Like0
Like0Like1Like0