私は配列を持っています:
ar = ["p=abhZRAh7Un", "a=2", "c=1", "l=3033102", "r=1", "rt=mr", "pid=136330865", "pdid=AiOIhH2vzMPqvhYkxXOxeA%3D%3D", "lks=54.0311", "fks=54.0311"]
等号の右側にあるものは何でも、キー、、、などと値をp
使用してハッシュに変換する必要があります。Rubyでそれを行うエレガントな方法は何ですか?a
c
Hash[ar.map{|s| s.split("=")}]
require 'cgi'
ar = ["p=abhZRAh7Un", "a=2", "c=1", "l=3033102", "r=1", "rt=mr", "pid=136330865", "pdid=AiOIhH2vzMPqvhYkxXOxeA%3D%3D", "lks=54.0311", "fks=54.0311"]
CGI.parse(ar.join('&'))
出力:
=> {"rt"=>["mr"], "fks"=>["54.0311"], "pid"=>["136330865"], "lks"=>["54.0311"], "pdid"=>["AiOIhH2vzMPqvhYkxXOxeA=="], "r"=>["1"], "l"=>["3033102"], "c"=>["1"], "a"=>["2"], "p"=>["abhZRAh7Un"]}