Building querystrings with ruby

golfing? :slight_smile:

"?#{map{|k, v| "#{CGI.escape k}=#{CGI.escape v}"} * '&'}"

cheers

Simon

···

-----Original Message-----
From: Paul Battley [mailto:pbattley@gmail.com]
Sent: Wednesday, March 15, 2006 10:09 AM
To: ruby-talk ML
Subject: Re: Building querystrings with ruby

On 15/03/06, Paul Battley <pbattley@gmail.com> wrote:
> And this is shorter still:
>
> "?" << to_hash.map{ |kv| kv.map{ |e| CGI.escape(e)
}.join("=") }.join("&")

Ignore my stupidity above; this is shorter and less redundant:

"?" << map{ |kv| kv.map{ |e| CGI.escape(e) }.join("=") }.join("&")

Paul.

All right then! :slight_smile:

"?"<<map{|h|h.map{|e|CGI.escape(e)}*'='}*'&'

Paul.

···

On 15/03/06, Kroeger, Simon (ext) <simon.kroeger.ext@siemens.com> wrote:

golfing? :slight_smile:

"?#{map{|k, v| "#{CGI.escape k}=#{CGI.escape v}"} * '&'}"