Method: String#word_wrap!

Defined in:
lib/core/facets/string/word_wrap.rb

#word_wrap!(col_width = 80) ⇒ Object

As with #word_wrap, but modifies the string in place.

CREDIT: Gavin Kistner, Dayne Broderson



26
27
28
29
30
# File 'lib/core/facets/string/word_wrap.rb', line 26

def word_wrap!( col_width=80 )
  self.gsub!( /(\S{#{col_width}})(?=\S)/, '\1 ' )
  self.gsub!( /(.{1,#{col_width}})(?:\s+|$)/, "\\1\n" )
  self
end