rake可以取到当前执行的task对象和rake 命令行参数,虽然以前就可以用ENV这个常量取道,但是现在的先声名再用的做法更清晰~
[url]http://rake.rubyforge.org/files/doc/release_notes/rake-0_8_2_rdoc.html[/url]
[url]http://jasonseifer.com/2010/04/06/rake-tutorial[/url]
#rake namespace:demo arg1=oo arg2=xx
namespace :namespace do
task :demo, :arg1, :arg2 do |t , args|
#get current task
p t.name #=> "namespace:demo"
#get task arguments
p args.arg1 + args.arg2 #=> "ooxx"
p t.name_with_args #=> "namespace:demo[arg1,arg2]"
#envirenment
p ENV #=> {"arg1"=>"oo", "arg2"=>"xx", ...}
end
end
[url]http://rake.rubyforge.org/files/doc/release_notes/rake-0_8_2_rdoc.html[/url]
[url]http://jasonseifer.com/2010/04/06/rake-tutorial[/url]