class String def word_shorten ( length = 30 ) if self.length >= length short = self[0, length].split(/\s/) short[0, short.length-1].join(" ") + ' …' else self end endendputs "Lorem ipsum dolor sit amet.".word_shorten(10)