Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Get Variable Name from object_id

Reply
Thread Tools

Get Variable Name from object_id

 
 
Evan Moseman
Guest
Posts: n/a
 
      01-12-2008
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
 
Reply With Quote
 
 
 
 
Tim Hunter
Guest
Posts: n/a
 
      01-12-2008
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.rubyforge.org/
RMagick 2: http://rmagick.rubyforge.org/rmagick2.html

 
Reply With Quote
 
 
 
 
Todd Benson
Guest
Posts: n/a
 
      01-13-2008
On Jan 12, 2008 5:13 PM, Tim Hunter <(E-Mail Removed)> 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

 
Reply With Quote
 
botp
Guest
Posts: n/a
 
      01-13-2008
On Jan 13, 2008 6:44 AM, Evan Moseman <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
#<Object:0x2c1c8f0> <--- why is the displayed number == object_id*2 Meinrad Recheis Ruby 5 06-07-2007 05:23 PM
get info from object_id Peņa, Botp Ruby 4 06-01-2007 03:20 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
which one is object_id? uncutstone Ruby 1 05-09-2006 07:30 AM
A interesting obervation about object_id method Hank Gong Ruby 6 12-21-2005 10:40 PM



Advertisments