在参数声明中使用参数值

时间:2013-02-21 11:01:55

标签: ruby thor

我希望根据先前声明的参数的值指定参数的默认值。在此示例中,handlerSendPort默认值应为handlerRecvPort + 1

require "thor/group"  
module Noov
  class App < Thor::Group
    include Thor::Actions

    argument :name, type: :string, desc: "The name of the project to create"
    argument :handlerRecvPort, type: :numeric, desc: "The 0MQ recv port number on the handler side (random if not specified)", optional: true, default: rand(2**16-1024)+1024+1
    argument :handlerSendPort, type: :numeric, desc: "The 0MQ send port number on the handler side (recv port + 1 if not specified)", optional: true, default: handlerRecvPort+1
    argument :handlerUUID, type: :string, desc: "The mongrel2 server UUID (project name if not specified)", optional: true, default: name
    desc "Creates a project directory for a new website. Fully equipped to support BDD with Cucumber"

  end
end

这失败了:

undefined local variable or method handlerRecvPort'for Noov :: App:Class(NameError)`

我意识到参数值在类评估的上下文中是不可用的(虽然我曾希望有一些使用它的元模型),那么我怎样才能访问参数值呢?

0 个答案:

没有答案