Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2013 22:03
Show Gist options
  • Save anonymous/5078515 to your computer and use it in GitHub Desktop.
Save anonymous/5078515 to your computer and use it in GitHub Desktop.
str = 'foo,bar,bar-foo,baz^key=value^key1=value1,bazfoo'
new_str = Hash[str.split(',').map{|s| k,*v = s.split('^'); [k.to_sym,v.empty? ? nil : Hash[v.map {|s|s.split('=')}.inject({}){|c,(k,v)| c[k.to_sym] = v; c}]]}] if str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment