Skip to content

Instantly share code, notes, and snippets.

@fnando
Created November 30, 2010 19:57
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 fnando/722283 to your computer and use it in GitHub Desktop.
Save fnando/722283 to your computer and use it in GitHub Desktop.
Remove indentation from all lines, based on the first one.
class String
def unindent
_, spaces = *match(/^([\t ]+)/)
spaces ? gsub(%r[^#{spaces}]ms, "") : self
end
end
html = <<-CODE.unindent
THIS IS JUST A TEST
AND THIS A TEXT SNIPPET THAT SHOULD
BE INDENTED ONLY TWO SPACES FROM LEFT.
CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment