Skip to content

Instantly share code, notes, and snippets.

@0xradical
Created November 11, 2013 17:48
Show Gist options
  • Select an option

  • Save 0xradical/7417269 to your computer and use it in GitHub Desktop.

Select an option

Save 0xradical/7417269 to your computer and use it in GitHub Desktop.
Dot-separated to hash using recursive lambda
hashify = ->(str, memo = []){ str =~ /\./ ? (r = str.split(/\./,2); {r[0] => hashify[r[1],memo << r[0]]}) : {str => [memo << str].join('.')} }
# hashify['a.b.c.d'] =>
# {"a"=>{"b"=>{"c"=>{"d"=>"a.b.c.d"}}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment