Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/string.rb
Instance Method Summary collapse
Instance Method Details
#wrap(width) ⇒ Object
2 3 4 5 6 7 8 9 10 |
# File 'lib/string.rb', line 2 def wrap(width) split("\n").collect { |line| if line.length > width line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip else line end } * "\n" end |