Skip to content

Instantly share code, notes, and snippets.

@liquorice
Created September 20, 2011 06:04
Show Gist options
  • Save liquorice/1228474 to your computer and use it in GitHub Desktop.
Save liquorice/1228474 to your computer and use it in GitHub Desktop.
truncate text to nearest word boundry
# 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(' ') + '...'
@liquorice
Copy link
Author

my ruby is very weak; would like to see a simpler way of doing this. anyone for golf?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment