Skip to content

Instantly share code, notes, and snippets.

@dramsay
Created November 17, 2008 19:59
Show Gist options
  • Save dramsay/25882 to your computer and use it in GitHub Desktop.
Save dramsay/25882 to your computer and use it in GitHub Desktop.
def truncate_comment(text, length=30, end_string="...")
pattern = %r(^(.{#{length}})(.*))
text.gsub(pattern) {$2.empty? ? $1 : $1 + '...'}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment