Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created November 15, 2008 10:39
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 apeiros/25229 to your computer and use it in GitHub Desktop.
Save apeiros/25229 to your computer and use it in GitHub Desktop.
class String
def reindent(to, tabwidth=nil)
indenter = (tabwidth ? " "*tabwidth : "\t")*to
initial = self[/\A[\t ]*/]
gsub(/^(?:#{initial})?/, indenter)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment