Created
September 20, 2011 06:04
-
-
Save liquorice/1228474 to your computer and use it in GitHub Desktop.
truncate text to nearest word boundry
This file contains hidden or 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
# truncate text without chopping words | |
# where d = text to truncate | |
# x = maximum amount of characters | |
(d.length <= x) ? d : d[0..x].split()[0...-1].join(' ') + '...' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
my ruby is very weak; would like to see a simpler way of doing this. anyone for golf?