Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Chao Lam http://blogs.coolchaser.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Truncate text with word boundaries in Ruby

   1  
   2    def truncate_words(text, length = 30, end_string = '')
   3      words = text.split()
   4      words[0..(length-1)].join(' ') + (words.length > length ? end_string : '')
   5    end
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS