Paul Battley
3/15/2006 9:07:00 AM
On 15/03/06, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> require "cgi"
> class Hash
> def query_string
> "?" << inject([]){|a,kv| a << [CGI.escape(kv.shift), CGI.escape(kvshift)].join("=") }.join("&")
> end
> end
Now here's somewhere I can use the handy trick I learned yesterday:
"?" << inject([]){ |a,(k,v)| a << [CGI.escape(k),
CGI.escape(v)].join("=") }.join("&")
But this is shorter:
"?" << inject([]){ |a,kv| a << kv.map{ |e| CGI.escape(e) }.join("=") }.join("&")
And this is shorter still:
"?" << to_hash.map{ |kv| kv.map{ |e| CGI.escape(e) }.join("=") }.join("&")
Paul.