Skip to content

Instantly share code, notes, and snippets.

@quirkey
Created December 2, 2008 15:46
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 quirkey/31143 to your computer and use it in GitHub Desktop.
Save quirkey/31143 to your computer and use it in GitHub Desktop.
def truncate_words(text, length = 30, truncate_string = "..." )
return if text.nil?
words = text.split
words.length > length ? words[0...length].join(" ") + truncate_string : text
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment