On Dec 23, 2009, at 01:37 , Alexandre M. wrote:
Marc H. wrote:
I think it is a quite short topic actually.
Which operators are commonly overloaded in ruby?
I mean, when you need to use intensively operators, there are lots of
(small) issues, difference between 1.8.x and 1.9.x, difference with
JRuby with --1.9 switch… Actually, I’m using operators overloading for
a DSL to accept new If/Else/Elsif expressions, and have to deal with
those issues.
For example the unary +@ operator on symbols is not really working in
1.8.x.
How is it not working on symbols?
class Symbol
def +@
puts “YES #{self}”
end
def -@
puts “NO #{self}”
end
end
-:x # => NO x
+:x # => :x
+(:x) # => YES x
-(:x) # => NO x
+(:x) # => YES x
:x.send(:-@) # => NO x
:x.send(:+@) # => YES x
As well as the ! operator that was finally introduced in 1.9.x.
Have you filed any bugs (or even sent email) against ruby-core for the !
operator?
For the Fixnum, i didn’t find any documentation (until here) that states
that +@ operator for numeric are in fact consumed by the parser as
literals…
Did you actually look at a grammar for ruby? There has been one online
for just about forever (granted it is from 1.4, but I don’t think it has
changed all that much in this arena). You can also look at ParseTree’s
output, or ruby_parser’s, or, or, or…