我试图弄清楚Thor gem如何创建这样的 DSL(他们的 README 中的第一个示例)
class App < Thor # [1]
map "-L" => :list # [2]
desc "install APP_NAME", "install one of the available apps" # [3]
method_options :force => :boolean, :alias => :string # [4]
def install(name)
user_alias = options[:alias]
if options.force?
# do something
end
# other code
end
desc "list [SEARCH]", "list all of the available apps, limited by SEARCH"
def list(search="")
# list everything
end
end
具体来说,它如何知道映射desc
和method_options
调用哪个方法?