Elegant way of shorten a text string
1 2 def shorten (string, count = 30) 3 if string.length >= count 4 shortened = string[0, count] 5 splitted = shortened.split(/\s/) 6 words = splitted.length 7 splitted[0, words-1].join(" ") + ' ...' 8 else 9 string 10 end 11 end