簡體   English   中英

如何在Thor方法中檢索當前命令名稱?

[英]How can I retrieve the current command name in a Thor method?

我有幾個互相依賴的雷神任務。 我想訪問當前正在運行的名稱,以便可以在記錄器消息中使用它。

我可以使用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方法。 它以字符串形式返回當前執行堆棧。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM