ruby-on-rails - 如何在 ruby 中找到调用者类?
问题描述
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
我的项目名称在哪里
推荐阅读
- javascript - 使用 javascript 的动态 HTML 分页
- react-native - 未定义的评估 frames.endCoordinates.height
- python - Python中是否有一种干净的方法可以将列表或单个元素转换为特定格式?
- javascript - 从 Firebase 到 Merriam-Webster 的超时请求到期请求
- spring-boot - Spring-boot 服务未作为 Java 11 中的 Eureka 发现客户端启动
- amazon - 上传发票亚马逊 MWS
- html - 网站响应标签适用于苹果设备但不适用于安卓
- c# - 我在哪里可以在天蓝色应用程序中找到用于创建“ClientCredential”对象的“authenticationKey”值
- c - 位操作 - 仅更改最后 4 位
- javascript - 如何根据类型和条件附加 vuetify 图标?