我正在编写一个 Rake 任务,我想将一个数组作为参数之一传递。这是我目前拥有它的方式。
task :change_statuses, :ids, :current_status, :new_status do |task, args|
puts "args were #{args.inspect}"
end
我尝试通过以下方式运行任务:
# First argument as array
rake "change_statuses[[1,2,3], active, inactive]"
# First argument as string
rake "utility:change_account_statuses['1,2,3', foo, bar]"
我的预期输出是:
args were {:ids=> [1,2,3], :current_status=> 2 , :new_status=> 3}
但是,我在每种情况下的实际输出是:
args were {:ids=>"[1", :current_status=>"2", :new_status=>"3]"}
如何将数组传递给 Rake 任务?