Skip to content

Instantly share code, notes, and snippets.

@nathankleyn
Created February 6, 2012 11:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathankleyn/1751694 to your computer and use it in GitHub Desktop.
Save nathankleyn/1751694 to your computer and use it in GitHub Desktop.
Gist #5 For "Functional Programming Techniques With Ruby: Part I"
def module_split(module_path, separator = "::")
modules = module_path.split(separator)
modules.length.downto(1).map { |n| modules.first(n).join(separator) }
end
module_split("W::X::Y::Z")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment