P
Perry Smith
I'm trying to debug a problem I have with YAML. When I do:
puts "#{foo.class}"
I get (for example) Xyz
but I know that foo is not really of class Xyz. I think it is an
YAML::Object. The reason this happens is because to_s has been
overridden.
How can I get the real name of the class of an object?
I think this is what YAML::Object is doing:
#! /usr/bin/env ruby
class Xyz
def self.to_s
"dog"
end
end
x = Xyz.new
puts "#{x.class}"
I get "dog" instead of Xyz. How can I get Xyz in this case?
puts "#{foo.class}"
I get (for example) Xyz
but I know that foo is not really of class Xyz. I think it is an
YAML::Object. The reason this happens is because to_s has been
overridden.
How can I get the real name of the class of an object?
I think this is what YAML::Object is doing:
#! /usr/bin/env ruby
class Xyz
def self.to_s
"dog"
end
end
x = Xyz.new
puts "#{x.class}"
I get "dog" instead of Xyz. How can I get Xyz in this case?