S
Srijayanth Sridhar
Hello,
Let us say we have a hash:
a = Hash.new
Can I do something of this sort:
class Hash
def who_am_i?
"#{self.symbol}"
end
end
Where self.symbol gives me "a"?
I basically want the variable name. I looked a bit and saw that you
could intern a symbol from a string, but is there an easy way to get
the name of a variable from within the object itself? I am writing a
to_xml method for hashes and it would be immensely helpful if I can
use the name of the variable as the root element.
Thank you,
Jayanth
Let us say we have a hash:
a = Hash.new
Can I do something of this sort:
class Hash
def who_am_i?
"#{self.symbol}"
end
end
Where self.symbol gives me "a"?
I basically want the variable name. I looked a bit and saw that you
could intern a symbol from a string, but is there an easy way to get
the name of a variable from within the object itself? I am writing a
to_xml method for hashes and it would be immensely helpful if I can
use the name of the variable as the root element.
Thank you,
Jayanth