Huayin Wang <wang / rjka.com> writes:

> does this have anything to do with the following?
> 
> irb(main):001:0> -2 ** 2
> -4
> irb(main):002:0>

Sure is!

You can play around with trace_func to see what's happening:

     set_trace_func proc{|event, file, line, id, binding,klass,*rest|
       print "#{event} at #{file}:#{line} - #{id.id2name} in #{klass}\n"
     }

     -2**2

produces:

     line at t.rb:5 -  in false
     c-call at t.rb:5 - ** in Fixnum
     c-return at t.rb:5 - ** in Fixnum
     c-call at t.rb:5 - -@ in Fixnum
     c-return at t.rb:5 - -@ in Fixnum

It calls the ** method in Fixnum, generating a new Fixnum, then calls
the -@ (unary minus) method in that object.

Until Matz's change, you can get around this with (-2)**2

Regards

Dave