Sha256: c08f87edd2a442d8de49e2ccda63435b9c3ade98a6dd64e0f8edb052195b08cb
Contents?: true
Size: 969 Bytes
Versions: 1
Compression:
Stored size: 969 Bytes
Contents
class String # Word wrap a string not exceeding max width. # # require 'facet/string/word_wrap' # # puts "this is a test".word_wrap(4) # # _produces_ # # this # is a # test # def word_wrap(max=80) c = dup c.word_wrap!(max) c end # 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
facets-0.6.3 | lib/facet/string/word_wrap.rb |