Skip to content

Instantly share code, notes, and snippets.

@ahawthorne
Created March 28, 2012 17:48
Show Gist options
  • Save ahawthorne/2228664 to your computer and use it in GitHub Desktop.
Save ahawthorne/2228664 to your computer and use it in GitHub Desktop.
ruby strip_tags and text_trim
def strip_tags(text)
return text.gsub(/<\/?[^>]*>/, "")
end
def text_trim(text, len, trail = '...')
if len < text.size then
text.scan(/.{1,#{len}} /) do |match|
return match.rstrip + trail
break
end
else
return text
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment