From: James Edward Gray II Date: 2006-12-11T22:56:54+09:00 Subject: Re: can it be shorter? On Dec 10, 2006, at 11:20 PM, WuyaSea Operator wrote: > doing formating, i need to break a long line of words to roughly 80 > chars per line, below is what I got > > def break_line(text) > return text if text.size < 80 > > i = text.index(' ', 79) > text[0..i] + "\n" + break_line(text[i+1..-1]) > end > > > can it be any shorter, more rubyish? Thank you. def break_line(text) text.gsub!(/(.{1,80}|\S{81,})(?: +|$\n?)/, "\\1\n") end James Edward Gray II