Created
November 11, 2013 17:48
-
-
Save 0xradical/7417269 to your computer and use it in GitHub Desktop.
Dot-separated to hash using recursive lambda
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
| 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