Mega Code Archive

 
Categories / Ruby / String
 

Wrap a string with new line sing

def wrap(s, width=78)   s.gsub(/(.{1,#{width}})(\s+|\Z)/, "\\1\n") end poetry = %q{It is an ancient Mariner, A "} puts wrap(poetry, 20)