Sha256: 6ae3c342231f70e9d0f678d7d9b3b2c93c9810f72a7e40dacb4d3838a9ac0dfb

Contents?: true

Size: 700 Bytes

Versions: 3

Compression:

Stored size: 700 Bytes

Contents

class String
  # Like #word_wrap, but modifies the string in place.
  def word_wrap!(max=80)
    raise ArgumentError, "Wrap margin too low: #{n}" if max <= 2
    #gsub!( Regexp.new( "(.{1,#{max-1}}\\w)\\b\\s*" ), "\\1\n")
    gsub!( /(.{1,#{max-1}}\S)([ ]|\n)/, "\\1\n")
  end
end


=begin
# --- dev test ---

if $0 == __FILE__

s = "PackMule is a rake front-end thisisaverylongwordtoseeifgetsdivededornot"
s << " tool that makes it easy to 'pack-out' your Ruby packages. PackMule can run tests, build"
s << " .tgz and .zip packages, create gem packages, perform a manual"
s << " install, generate rdocs and publish them, and CVS support"
s << " might be added soon."

puts s.word_wrap(60)

end
=end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
facets-0.7.0 lib/facet/string/word_wrap%21.rb
facets-0.7.1 lib/facet/string/word_wrap%21.rb
facets-0.7.2 lib/facet/string/word_wrap%21.rb