Word Wrap

Wrap text to specified line width.

Code

General
text.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip

Parameters

Text to wrap

Maximum line width

Server

More Ruby Snippets