Method: String#wrap
- Defined in:
- lib/fat_core/string.rb
permalink #wrap(width = 70, hang = 0) ⇒ Object
[View source]
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fat_core/string.rb', line 84 def wrap(width=70, hang=0) offset = 0 trip = 1 result = '' while (s = slice(offset, width)) offset += width if trip == 1 width -= hang else s = (' ' * hang) + s end result << s + "\n" trip += 1 end # Remove the final newline before exiting result.strip end |