[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie: Equivalent to "this" keyword in Java?

Wes Gamble

3/27/2006 10:56:00 PM

If I am writing a method and I want to refer to the instance of the
object itself, do I use "self"? Can I use "this"? Is "this" an alias
for "self"?

Wes

--
Posted via http://www.ruby-....


3 Answers

Hal E. Fulton

3/27/2006 11:01:00 PM

0

Wes Gamble wrote:
> If I am writing a method and I want to refer to the instance of the
> object itself, do I use "self"? Can I use "this"? Is "this" an alias
> for "self"?

It's self. There's no alias, but you can say

this = self

if you want... ;)


Hal




Wilson Bilkovich

3/27/2006 11:01:00 PM

0

On 3/27/06, Wes Gamble <weyus@att.net> wrote:
> If I am writing a method and I want to refer to the instance of the
> object itself, do I use "self"? Can I use "this"? Is "this" an alias
> for "self"?
>

It's "self", and it can also be used to differentiate between local
variables and methods, in the (very rare, usually Rails-based)
situations where there can be ambiguity.


Wes Gamble

3/27/2006 11:20:00 PM

0

Got it. I was auto-creating a variable named "this" before :).

Wilson Bilkovich wrote:
> On 3/27/06, Wes Gamble <weyus@att.net> wrote:
>> If I am writing a method and I want to refer to the instance of the
>> object itself, do I use "self"? Can I use "this"? Is "this" an alias
>> for "self"?
>>
>
> It's "self", and it can also be used to differentiate between local
> variables and methods, in the (very rare, usually Rails-based)
> situations where there can be ambiguity.


--
Posted via http://www.ruby-....