Split post string into hash if(env['REQUEST_METHOD'] == 'POST')
  $post = {}
  post = env['rack.input'].read.split('&amp;')
  post_split = Array.new
  post.each{|x| post_split &lt;&lt; x.split('=')}
  post_split.each{|x|
    $post[x[0]] = x[1]
  }
end


What would be a nice way to do this? I have a string like:

"a=b&amp;c=d"


and i'm trying to get it into a hash like

{:a=&gt;'b',:c=&gt;'d'}


This code works but it is just terrible, and I can't access the keys with

$post[:a] 


only 

$post['a']
better way of such parsing is not to reinvent the wheel and use existing ruby functionality

require "cgi"
post = CGI.parse "a=b&amp;c=d"
# =&gt; {"a"=&gt;["b"], "c"=&gt;["d"]}


hash values are arrays here, but it makes sense, as you can have several vars in your query string with the same name

for the second part of your question (accessing the keys as symbols) you can use .with_indifferent_access method provided by ActiveSupport (it is already loaded if you use rails)

post.with_indifferent_access[:a]
# =&gt; ["b"]