DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

Wrap Text In Ruby

06.29.2006
| 4423 views |
  • submit to reddit
        Posted by Allen Odgaard to 

http://macromates.com/blog/archives/2006/06/28/wrapping-text-with-regular-expressions/

def wrap_text(txt, col = 80)
  txt.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/, "\\1\\3\n") 
end