Over a million developers have joined DZone.

Wrap Text In Ruby

·
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
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}