Created
May 28, 2012 15:08
-
-
Save iNecas/2819636 to your computer and use it in GitHub Desktop.
Align indented
This file contains 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
# 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