Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created October 6, 2008 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/15036 to your computer and use it in GitHub Desktop.
Save apeiros/15036 to your computer and use it in GitHub Desktop.
class String
def segments
segments = split(/\./)
while segments.size > 1
yield(segments.join('.'))
segments.pop
end
yield('.')
end
end
class String
def segments
str = dup
begin
yield(str)
end while str.sub!(/\.[^.]+$/, '')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment