Created
March 31, 2014 10:12
-
-
Save rwoeber/9889262 to your computer and use it in GitHub Desktop.
Query string to hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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