I'm so lost. I know how to use caller to get the caller method, but what do you use the get the caller class?
For example:
class Testing
def return_caller_class
return caller_class
end
end
class Parent
attr_accessor :test_me
def initialize
self.test_me = Testing.new
end
end
class Child < Parent
end
class GrandChild < Child
end
test_Parent = Parent.new
test_Child = Child.new
test_GrandChild = GrandChild.new
puts test_Parent.test_me.return_caller_class => Parent
puts test_Child.test_me.return_caller_class => Child
puts test_GrandChild.test_me.return_caller_class => GrandChild
Thank you!!!
Edit:
I've tried to do the following
class Testing
def return_caller_class
return caller[0][/`.*'/][1..-2]
end
end
And the output is:
{"
"=>Parent}
{"
"=>Child}
{"
"=>GrandChild}
To explain better about my question.
I would the output to display this instead
Parent
Child
GrandChild