From: John W Higgins Date: 2009-09-15T10:32:24+09:00 Subject: Re: URL format --0016e646a47401d6e2047393c110 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Sep 14, 2009 at 5:58 PM, Re BR wrote: > I have the following hash myhash > { "inter" => "team", "shirt" => "stripe" } > > desired output > > inter=team&shirt=stripe > > I tried url_for myhash but got undefined method `url_for' for > The single line answer would be hsh = { "inter" => "team", "shirt" => "stripe" } hsh.to_a.map{|e| e.join('=')}.join('&') # 'inter=team&shirt=stripe' Broken down hsh = { "inter" => "team", "shirt" => "stripe" } ary = hsh.to_a #[['inter', 'team'], ['shirt', 'stripe']] - take the hash and switch into array new_ary = ary.map{|e| e.join('=')} #['inter=team', 'shirt='stripe'] - take the array and join the inner arrays using a = final = new_ary.join('&') # 'inter=team&shirt=stripe' take the remaining array and join the element with & John --0016e646a47401d6e2047393c110--