Ruby 在 rake 中怎么传参数?

lb563 · February 26, 2012 · Last by ashchan replied at February 26, 2012 · 7693 hits

在一些 rake 脚本中,有些时候要传参数给脚本,用什么方法来传递呢? 我所知道的就加一个 ENV 常量例如:

desc "test"
task :test do
  puts "params #{ENV[parmas]}"
end

如果使用的话:

rake test params="test"

这样就会把"test"传到脚本 中去 我想问为什么 必须用 ENV 这个常量呢?

向进程传递参数的传统做法就是环境变量,虽然 rake 也有其它特有的传参方式

task :test, :p1 do |t, args|
  # args[:p1] will be "test"
end

rake test["test"]
You need to Sign in before reply, if you don't have an account, please Sign up first.