Oops, my bad, wrong mailing list. Please see fowared message:
···
---------- Forwarded Message ----------
Subject: Can’t define +@ for Symbol (plus ruby install problem)
Date: Thursday 11 December 2003 08:30 pm
From: “T. Onoma” transami@runbox.com
To: ruby-core@ruby-lang.org
I wanted to see if the +@ problem was fixed in 1.8.1 preview 3 but when I do
make install
I’m told that ruby’s already installed and to use the -r option to reinstall.
But make install dosn’t seem to recognize the -r option. Is there something
else I’m supposed to do?
As for +@: -@ works fine but +@ acts as if it doesn’t exist unless one uses
paraethesis.
class Symbol
def -@; “-#{self}”; end
def +@; “+#{self}”; end
end
p -(:s) # => "-s"
p -:s # => "-s"
p +(:s) # => "+s"
p +:s # => :s
Is there something about this that makes it unworkable? I hope not, since
it’s an important feature of a project of mine.
+@ and -@ are used to define unary operators for + (plus) and - (minus). It is
a special notation so that ruby knows what you’re are talking about. Consider
that when you put a minus sign in front of a number you are actually calling
the -@ method of the Numeric class. For example, if your were defining it
yourself you would do it something like this:
class Numeric
def -@
return self * -1
end
end
As far as I know -@ and +@ are the only unary operators that can be defined.
HTH,
T.
···
On Friday 12 December 2003 04:06 am, dhtapp wrote: