Skip to content

Instantly share code, notes, and snippets.

@nu7hatch
Created October 11, 2010 21:59
Show Gist options
  • Save nu7hatch/621310 to your computer and use it in GitHub Desktop.
Save nu7hatch/621310 to your computer and use it in GitHub Desktop.
# Line size can be calculated with system stty command (it works on linux/unix
# and windows):
#
# `stty size`.split.last.to_i
#
def line_break(text, line_size, delim="\n")
words, result, sum = text.split, [], 0
words.each do |word|
result << delim and sum=0 if (sum+word.size) > line_size
result << word+" "
sum += word.size+1
end
result.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment