class WordWrap::Wrapper
def wrap
def wrap output = [] @text.lines do |line| line.chomp! "\n" if line.length > @width new_lines = split_line(line, @width) while new_lines.length > 1 && new_lines[1].length > @width output.push new_lines[0] new_lines = split_line new_lines[1], @width end output += new_lines else output.push line end end output.map { |s| s.rstrip! } output.join("\n") + "\n" end