Created
October 11, 2010 21:59
-
-
Save nu7hatch/621310 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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