Created
March 22, 2012 21:46
-
-
Save cymen/2164828 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
def first(string, length) | |
string[0..length-1] | |
end | |
def rest(string, index) | |
if string[index] == " " | |
index += 1 | |
end | |
return string[index..-1] | |
end | |
def wrap(string, column) | |
if string.length <= column | |
return string | |
end | |
index = string[0..column].rindex(" ") || column | |
return first(string, index) + "\n" + wrap(rest(string, index), column) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment