Last active
December 13, 2015 19:38
-
-
Save nyarly/4964167 to your computer and use it in GitHub Desktop.
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
def align(string) | |
lines = string.split(/\n/) | |
first = lines.shift | |
match = /^(\s*)<<</.match(first) | |
unless(match.nil?) | |
return lines.map do |line| | |
unless /^#{match[1]}|^\s*$/ =~ line | |
raise Errors::UnderIndented, line | |
end | |
line.sub(/^#{match[1]}/, "") | |
end.join("\n") | |
end | |
return string | |
end | |
Use like: | |
align(<<-EOS) | |
<<< | |
Some left aligned | |
text | |
EOS | |
And know that no matter how the heredoc gets intented, the string that results will be left aligned to the <<< |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment