Open ryanong opened 9 years ago
I did some work on this in the train yesterday. I wrote some tests and gave method invocation precedence over unary operators. I think this is the right approach and also the approach Ruby takes.
However, Scribble parses negative integers (ie. -1
) as a positive integer and a unary operator. But in the case of -1.abs
the minus should take precedence over the method invocation. Ruby manages this by parsing the minus as part of the integer instead of as an unary operator. I'll try to implement something similar.
edit: ... gave method invocation precedence over unary operators ...
1.9.3-p551 :002 > Fixnum.send :undef_method, :-@
=> Fixnum
1.9.3-p551 :003 > -(1)
NoMethodError: undefined method `-@' for 1:Fixnum
from (irb):3
from /Users/stefan/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'
1.9.3-p551 :004 > -1
=> -1
1.9.3-p551 :005 > --1
NoMethodError: undefined method `-@' for -1:Fixnum
from (irb):5
from /Users/stefan/.rvm/rubies/ruby-1.9.3-p551/bin/irb:12:in `<main>'
1.9.3-p551 :006 >
That is some voodoo there. Great example!
scribble parses
!student.enrolled?
=>student.not.enrolled?
instead of
!student.enrolled?
=>student.enrolled?.not
Work around
!(student.enrolled?)