Here is a way I found out I can pass pass arguments to Symbol key of a hash.
task :test,:server do |t,args|
puts args.server
puts end_points[:"#{args.server}"]
end
Definition of end_points
end_points = { :dev ==> "http://mysite.com" }
This is how I call this rake task:
rake test[dev]
Is there a cleaner way to pass args.server as key of end_points.
“Cleaner” is a matter of perspective, but you can write
puts end_points[args.server.to_sym]if you dislike all that punctuation and just want to make the intent a bit clearer.