From: Robert Dober Date: 2007-05-06T06:06:51+09:00 Subject: Re: How can I output an object/variable's name? On 5/5/07, John Joyce wrote: > Suppose I have an object : > > a = 3 > > I want to output the name a and the contents 3 > Outputing the contents is no problem. > Is there a method to output the name of the variable (object) No there is no way to output the name of a variable as a variable is one of the view concepts in Ruby that are not directly accessible from inside Ruby. When it comes to objects things change of course, some objects have name properties as e.g. classes irb(main):002:0> A=Class.new => A irb(main):003:0> A.name => "A" But be aware that it is the object and not the constant referring to it who has the name, as one can easily see... irb(main):007:0* b = Class.new => # irb(main):008:0> b.name => "" irb(main):009:0> C = b => C irb(main):010:0> C.name => "C" irb(main):011:0> b.name => "C" this is maybe a little bit confusing but that is what ruby does when a class object is assigned to a constant. Robert -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw