簡體   English   中英

在Thor中跨類調用

[英]Cross class invoke in Thor

我正在嘗試從另一個thor類調用thor類。

class Foo < Thor
  desc "hello", "some description"
  def hello
    puts "Hello from Foo class"
  end
end

class Bar < Thor
desc "hello", "some description"
  def hello
    puts "Hello from Bar class"
    # ==> HERE I WANT TO CALL HELLO FROM FOO CLASS <==
  end
end

有invoke方法,但可以在同一類中調用方法。 有沒有辦法進行跨類的學習? 我假設正確的方法將使用Thor框架。

編輯

我正在嘗試一個將任務委托給其他班級的班級。 例如,您調用foo bar list ,主類Foo使用方法列表將其委托給Bar類,或者將foo module find 1委托給foo module find 1 ,並使用方法find和參數1將其委托給Module類。

我從未使用過Thor,但我認為通過在此處查看規范https://github.com/wycats/thor/blob/master/spec/invocation_spec.rb

這將是

Foo.new.invoke(:hello)

暫無
暫無

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

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