Hi all, a quick Ruby question for you:
params = {:q => "A query",:foo => "bar",:nasty => "Schrödinger's cat"}
p do_it(params)
=> q=A%20query&foo=bar&nasty=Schr%C3%B6dinger%27s+cat
(I think ö encodes like that, excuse me if its wrong) Is there a simpler way to do this than the following?:
def do_it(params)
out = []
params.each_pair{|key,val|
out.push "#{CGI.escape(key.to_s)}=#{CGI.escape(val)}"
}
out.join("&")
end
I'm not looking to start a war over the 'best' way to do this - its just this method seems very kludgey and un-ruby like! Any tips?