Sha256: da3bc99b306457b15994118c30ac9b256e7cf26dca0f8cf544ca10c45a5f1b17

Contents?: true

Size: 333 Bytes

Versions: 7

Compression:

Stored size: 333 Bytes

Contents

class String

  # Line wrap at width.
  #
  #   puts "1234567890".line_wrap(5)
  #
  # _produces_
  #
  #   12345
  #   67890
  #
  #  CREDIT: Trans

  def line_wrap(width, tabs=4)
    s = gsub(/\t/,' ' * tabs) # tabs default to 4 spaces
    s = s.gsub(/\n/,' ')
    r = s.scan( /.{1,#{width}}/ )
    r.join("\n") << "\n"
  end

end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
facets-2.4.0 lib/facets/string/line_wrap.rb
facets-2.4.1 lib/facets/string/line_wrap.rb
facets-2.4.2 lib/core/facets/string/line_wrap.rb
facets-2.4.3 lib/core/facets/string/line_wrap.rb
facets-2.4.4 lib/core/facets/string/line_wrap.rb
facets-2.4.5 lib/core/facets/string/line_wrap.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/string/line_wrap.rb