如何向Ruby程序发送参数

时间:2017-03-31 11:53:07

标签: ruby rake

我尝试了这段代码,以便向Ruby程序发送参数:

namespace :tnx do

  require_relative "transactions.rb"
  include Cnp_transactions_modes

  task :generate, [:clean_all] => [:environment]  do |t, args|

    if args[: clean_all] == 'true'
      // something
    end

    if args[:times]
      Cnp_transactions_modes.create_tnx(args[:times])
    else 
     puts "\nSet some number\n"
    end    
  end
end

当我以这种方式运行代码时:

bundle exec rake test:generate['true','30']

我得到Set some number

您能否提供一些如何修复代码的建议?

1 个答案:

答案 0 :(得分:0)

尝试像这样声明

task :generate, [:clean_all, :times] => [:environment]  do |t, args|

并像这样打电话

bundle exec rake tnx:generate['true','30']