如何将浮点数作为rake任务参数传递?

时间:2014-06-13 05:04:26

标签: ruby floating-point arguments rake

如何在rake任务中将float number作为参数传递

desc "example rake"
task :to_store_number, [:number1, :number2] do |t, args|
  a = "#{args[:number1].to_f}" * "#{args[:number2].to_f}"
  puts a
end

出现错误“TypeError:没有将String隐式转换为整数”

1 个答案:

答案 0 :(得分:1)

传递像args [:number]这样的参数而不是"#{args [:number]}"修好了

desc "example rake"
task :to_store_number, [:number1, :number2] do |t, args|
  a = args[:number1].to_f * args[:number2].to_f
  puts a
end