parse a HTTP query string in the shortest possible way.
q = "query1=apa&query2=apa2"
Hash[q.split("&").collect{|a| a.split("=")}.flatten]
=> {"query1"=>"apa", "query2"=>"apa2"}
Hash[*q.split(/=|&/)]
reference url:
http://refactormycode.com/codes/1058-parse-a-querystring
没有评论:
发表评论