Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_extensions.rb

Overview

Adds String#wrap, which can be used to wrap at a particular column.

Authors

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

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