[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How Can an Object Read its Own Name
From: |
Brian Casiello |
Subject: |
Re: How Can an Object Read its Own Name |
Date: |
Mon, 18 Jan 2021 22:07:43 -0500 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 |
I'm a Smalltalk newbie, but I'll give this a shot, and hopefully learn
something!
Consider
Foo := Bar new .
Sna := Foo .
Foo and Sna are two different names for the exact same object. Which one
is its unique name?
How to handle would depend on exactly what you're trying to accomplish.
One possibility is to give the object a unique name when it is
constructed using an instance variable. You'd do something like
Foo := Bar newWithUniqueName: 'Kilroy' .
The name would carry along with the object, no matter what variable(s)
it happens to be assigned to. It could even be part of a collection, not
assigned to a single named variable at all, but the object would still
know its own name.
If that doesn't meet your requirements, you really need to know the name
of the (a) variable that the object is assigned to, I'm afraid that's
beyond me.
HTH,
Brian
On 1/18/2021 9:09 PM, Gary Highberger wrote:
Hi Everyone,
I'd like for an object to be able to send a message with it's unique name
as an argument.
For example:
The Foo instance of the class Bar sends a message with an argument of Foo.
The Sna instance of the class Bar sends a message with an argument of Sna.
Foo := Bar new .
Sna := Bar new .
I tried to use self but to no avail.
Many thanks,
Gary