Skip to content

Instantly share code, notes, and snippets.

@jvantuyl
Created February 13, 2010 05:42
Show Gist options
  • Save jvantuyl/303272 to your computer and use it in GitHub Desktop.
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.
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