Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created May 28, 2012 15:08
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 iNecas/2819636 to your computer and use it in GitHub Desktop.
Save iNecas/2819636 to your computer and use it in GitHub Desktop.
Align indented
# shift indented text to the left as much as possible
def align_indented(text)
shift_left = text.lines.map { |l| l[/^\s*/].size }.min
text.lines.map { |l| l[shift_left..-1] }.join
end
puts align_indented(<<TEXT)
this is some
indented text
we would like to
get to the left
as much as possible
but keep the hierarchy
TEXT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment