Forum: Ruby +@ and -@ methods ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cd1de7e6a1ff7903b249edc2a4a35b34?d=identicon&s=25 gaurav.v.bagga@gmail.com (Guest)
on 2007-04-24 14:00
(Received via mailing list)
Hi all,

Mostly when I do instance.methods.sort in irb, the list contains +@
and -@ what are these methods and how used.
I'll appreciate if someone helps me with this.

Reagrds
Gaurav V Bagga
Cd1de7e6a1ff7903b249edc2a4a35b34?d=identicon&s=25 gaurav bagga (Guest)
on 2007-04-24 14:06
(Received via mailing list)
Sorry I forgot to mention
when I do 1.methods.sort ,Is it something to do with unary operations?
7914035d29e46e9207a81f2c52f9f96f?d=identicon&s=25 Abhijit Gadgil (Guest)
on 2007-04-24 14:35
(Received via mailing list)
Hi,

On 4/24/07, gaurav bagga <gaurav.v.bagga@gmail.com> wrote:
> Sorry I forgot to mention
> when I do 1.methods.sort ,Is it something to do with unary operations?

1 is an object of type Integer

1.methods is a method in the Object Integer (which outputs an Array of
methods for the integer) and .sort is a method on an Object of Type
Array (which sorts the contents of the Array)

> On 4/24/07, gaurav.v.bagga@gmail.com <gaurav.v.bagga@gmail.com> wrote:
> >
> > Hi all,
> >
> > Mostly when I do instance.methods.sort in irb, the list contains +@
> > and -@ what are these methods and how used.
> > I'll appreciate if someone helps me with this.

From the pickaxe book +@ is a unary + operator simply returns the
receivers value and -@ returns the negated value for Numeric Objects
(floats / Integers)



> --
> Cheers
> Gaurav
> http://java-n-coffee.blogspot.com
> http://rorwebser.blogspot.com
> http://eclipsetrip.blogspot.com
>


--

अभिजीत

[written in http://www.paahijen.com/scratchpad]

[http://www.paahijen.com]
This topic is locked and can not be replied to.