[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Get Variable Name from object_id

Evan Moseman

1/12/2008 10:41:00 PM

If I am perusing through the each_object loop and find the objects I'm
interested in, how can I get their variable names?

Thanks!

--
Evan
3 Answers

Tim Hunter

1/12/2008 11:13:00 PM

0

Evan Moseman wrote:
> If I am perusing through the each_object loop and find the objects I'm
> interested in, how can I get their variable names?
>
> Thanks!
>
> --
> Evan
>

You can't. Variables are just labels for objects. What if you have
something like this:

foo = MyClass.new
bar = foo

What's the variable name of the object? What about

ary = []
ary << bar

Now what's the variable name? What about this

def f(v)
puts v
end

f(ary[0])

Now what's the variable name?

--
RMagick: http://rmagick.ruby...
RMagick 2: http://rmagick.ruby...rmagick2.html

Todd Benson

1/13/2008 12:51:00 PM

0

On Jan 12, 2008 5:13 PM, Tim Hunter <TimHunter@nc.rr.com> wrote:
>
> Evan Moseman wrote:
> > If I am perusing through the each_object loop and find the objects I'm
> > interested in, how can I get their variable names?
> >
> > Thanks!
> >
> > --
> > Evan
> >
>
> You can't. Variables are just labels for objects. What if you have
> something like this:
>
> foo = MyClass.new
> bar = foo
>
> What's the variable name of the object? What about
>
> ary = []
> ary << bar
>
> Now what's the variable name? What about this
>
> def f(v)
> puts v
> end
>
> f(ary[0])
>
> Now what's the variable name?

I was going to reply in the same way, but I suppose it would be
interesting to call up names for objects if the names exist for the
object space (as nil or array for each object maybe?). Like
Object#references or something like that.

Todd

botp

1/13/2008 3:27:00 PM

0

On Jan 13, 2008 6:44 AM, Evan Moseman <evan.moseman@gmail.com> wrote:
> interested in, how can I get their variable names?

thinking about the subject, i think you want to refer to the object fr
a given object id, mayb try

ObjectSpace#_id2ref

kind regards -botp