Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有几个相互依赖的雷神任务。我想访问当前运行的名称,以便可以在记录器消息中使用它。
我可以使用该self对象来查找任务名称,但这是一个Thor::Sandbox::MyClass对象,并且该信息位于很深的位置。有人知道吸气剂吗?就像是:
self
Thor::Sandbox::MyClass
class MyCLI < Thor def hello puts "hello, I am the task #{self.taskname}" end end
可能这会起作用:
def fun puts __method__ end fun #=> :fun
也看caller方法。它以字符串形式返回当前执行堆栈。
caller