Skip to content

Instantly share code, notes, and snippets.

@rubypanther
Created February 21, 2010 19:34
Show Gist options
  • Save rubypanther/310486 to your computer and use it in GitHub Desktop.
Save rubypanther/310486 to your computer and use it in GitHub Desktop.
class String
def word_slice(range, max_extra_chars = 20)
offset = range.max + 1
string = self.slice(range)
if self[offset,max_extra_chars] =~ /(^[a-zA-Z0-9_-]+)/
string << $1
end
string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment