Created
February 13, 2010 05:42
-
-
Save jvantuyl/303272 to your computer and use it in GitHub Desktop.
Ruby to turn a delimited string into a list of successive parent paths.
This file contains 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
require 'pp' | |
def pathlist( st, delim ) | |
lst = pl_helper( (st.split delim), []) | |
lst.map! { |l| | |
l.join delim | |
} | |
end | |
def pl_helper( lst, accum ) | |
return accum if lst.empty? | |
accum.push lst[0..-1] | |
pl_helper lst[0..-2], accum | |
end | |
pp (pathlist "X::Y::Z","::") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment