From: "David A. Black" Date: 2009-09-15T10:40:21+09:00 Subject: Re: URL format Hi -- On Tue, 15 Sep 2009, John W Higgins wrote: > 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' No need for the to_a. You'll get a [key,value] array in e each time through by just mapping the hash. Note that the order might come out different; for example, on my machine anyway: >> hsh = { "inter" => "team", "shirt" => "stripe" } => {"shirt"=>"stripe", "inter"=>"team"} >> hsh.map {|entry| entry.join("=") }.join("&") => "shirt=stripe&inter=team" though I suspect it doesn't matter in this case. David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)