Skip to content

Instantly share code, notes, and snippets.

@cymen
Created March 22, 2012 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cymen/2164828 to your computer and use it in GitHub Desktop.
Save cymen/2164828 to your computer and use it in GitHub Desktop.
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