誰かが次の配列を次の形式のハッシュに変換するのを手伝ってもらえますか?
配列
[["0", {"checkbox_2"=>"on"}], ["2", {"checkbox_1"=>"on"}]]
ハッシュ
search=>{"checkbox_2"=>"on", "checkbox_1"=>"on"}
xs = [["0", {"checkbox_2"=>"on"}], ["2", {"checkbox_1"=>"on"}]]
search = {:search => xs.map { |n, h| h }.inject(:merge)}
# {:search=>{"checkbox_2"=>"on", "checkbox_1"=>"on"}}
arr = [["0", {"checkbox_2"=>"on"}], ["2", {"checkbox_1"=>"on"}]]
hash = Hash[arr.flatten.select{|e| e.is_a? Hash}.collect{|e| e.to_a.flatten}]
=> {"checkbox_2"=>"on", "checkbox_1"=>"on"}