Created
December 2, 2008 15:46
-
-
Save quirkey/31143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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