Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string_extensions.rb
Overview
Adds String#wrap, which can be used to wrap at a particular column.
Authors
-
Ben Bleything <[email protected]>
Copyright
Copyright © 2007 Laika, Inc.
This code released under the terms of the BSD license.
Version
$Id: string_extensions.rb 274 2007-07-25 21:06:42Z bbleything $
Instance Method Summary collapse
-
#wrap(line_width = 72) ⇒ Object
Wraps a string at the given column (or 72, if none provided).
Instance Method Details
#wrap(line_width = 72) ⇒ Object
Wraps a string at the given column (or 72, if none provided)
22 23 24 |
# File 'lib/string_extensions.rb', line 22 def wrap(line_width = 72) self.gsub(/\n/, "\n\n").gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").chomp end |