Guest User

Untitled

a guest
Feb 21st, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.19 KB | None | 0 0
  1. def truncate_words(text, length = 30, truncate_string = "..." )
  2. return if text.nil?
  3. words = text.split
  4. words.length > length ? words[0...length].join(" ") + truncate_string : text
  5. end
Add Comment
Please, Sign In to add comment