Can't define +@ for Symbol (plus ruby install problem)

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.

T.



T.

“T. Onoma” transami@runbox.com wrote in message
news:200312111731.02127.transami@runbox.com

Oops, my bad, wrong mailing list. Please see fowared message:

As for +@: -@ works fine but +@ acts as if it doesn’t exist unless one
uses
paraethesis.

Could someone take a quick minute to explain what this syntax is used for?

Thanks!

  • dan

As for +@: -@ works fine but +@ acts as if it doesn’t exist unless one uses
paraethesis.

Maybe the parser discards the +, since for numbers it usually is a no-op.

Peter

Hi, dan

+@ 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:

“T. Onoma” transami@runbox.com wrote in message
news:200312111731.02127.transami@runbox.com

Oops, my bad, wrong mailing list. Please see fowared message:

As for +@: -@ works fine but +@ acts as if it doesn’t exist unless one

uses

paraethesis.

Could someone take a quick minute to explain what this syntax is used for?

Thanks!

T. Onoma wrote:

As far as I know -@ and +@ are the only unary operators that can be defined.

One more, at least:

irb(main):001:0> class Foo; def ~@; “FOO”; end; end
=> nil
irb(main):002:0> ~Foo.new
=> “FOO”

I like this one because ~ is less suggestive than + and -, so it could
be used for a wider variety of concepts.