class A
def bar
B.new.foo
end
end
class B
def foo
#Here
"HELLO WORLD!"
end
end
A.new.bar
在 B#foo
中,
我怎样才能找到 class A
或任何其他引用或类名。
基本上是从哪个类调用的。
我试过这样的:
self.class
#B
self.class.superclass
#Object
最佳答案
为了获得整个堆栈,我通常会这样做:
caller.select {|x| x.include?("my_string") }
其中 my_string
是我的项目的名称
关于ruby-on-rails - 如何在 ruby 中找到调用者类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62357739/