From: James Coglan Date: 2008-09-20T23:02:42+09:00 Subject: Re: [QUIZ] One-Liners Mashup (#177 again) ------=_Part_3280_24065127.1221919835773 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline > > New puzzle: Provide a one-liner that can wrap a body of text at a > requested maximum length. A first guess... this destroys all original whitespace in the string, currently trying to fix that. class String def line_wrap(n = 80) split(/\s+/).inject{ |s,w| s + ("#{s.split("\n").last} #{w}".size > n ? "\n" : " ") + w } end end ------=_Part_3280_24065127.1221919835773--