module WordWrapTing

Constants

VERSION

Public Class Methods

wrap(str, max_len) click to toggle source
# File lib/word_wrap_ting.rb, line 8
def self.wrap(str, max_len)
  return str if str.length <= max_len

  break_col = str[0...max_len].rindex(' ') || max_len
  str[0...break_col].strip << "\n" << self.wrap(str[break_col..-1].strip, max_len)
end