My problem basically looks like this:
module Foo
class Bar
def self.who
self.class.to_s
end
end
end
class World < Foo::Bar
end
When I call World.who I don’t get "World" as a result, I get "Class". Some quick Googling didn’t yield anything useful, so hence I’m here hoping someone will know how to get the correct class name 🙂
If you’re calling
foo.barthen inside thebarmethod the value ofselfwill befoo. So when you callWorld.whothe value ofselfinsidewhoisWorld. SinceWorldis a class,World.classwill returnClass, so that’s what you get.To get back
"World"just callself.to_sorself.name(or justto_sorname).