Had some weird results when redefining the unary +
operator in Ruby on the Fixnum
class. Not exactly sure why things are happening the way they are
This answer adds additional details to mu's answer.
Just learned about ruby's Ripper class, and it shows what's happening pretty clearly:
require 'ripper'
p Ripper.sexp('2') # => [:program, [[:@int, "2", [1, 0]]]]
p Ripper.sexp('+2') # => [:program, [[:@int, "+2", [1, 0]]]]
p Ripper.sexp('+(2)') # => [:program, [[:unary, :+@, [:paren, [[:@int, "2", [1, 2]]]]]]]
p Ripper.sexp('++2') # => [:program, [[:unary, :+@, [:@int, "+2", [1, 1]]]]]