Skip to content

Instantly share code, notes, and snippets.

@rwoeber
Created March 31, 2014 10:12
Show Gist options
  • Select an option

  • Save rwoeber/9889262 to your computer and use it in GitHub Desktop.

Select an option

Save rwoeber/9889262 to your computer and use it in GitHub Desktop.
Query string to hash
# via https://twitter.com/RubyMotionTV/status/437503446166417409/photo/1
[3] pry(main)> s = 'key1=valueA&key2=valueB&key3=valueC'
#=> "key1=valueA&key2=valueB&key3=valueC"
[4] pry(main)> Hash[s.split(/[&=]/).each_slice(2).to_a]
#=> {"key1"=>"valueA", "key2"=>"valueB", "key3"=>"valueC"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment