提交 b422cda2 编写于 作者: X Xavier Noria

let String#strip_heredoc handle blank lines even if they are not indented

上级 58d0e2c2
require 'active_support/core_ext/object/try'
class String
# Strips indentation in heredocs.
#
......@@ -18,7 +20,7 @@ class String
# Technically, it looks for the least indented line in the whole string, and removes
# that amount of leading whitespace.
def strip_heredoc
indent = chomp.scan(/^\s*/).min.size
gsub(/^\s{#{indent}}/, '')
indent = scan(/^[ \t]*(?=\S)/).min.try(:size) || 0
gsub(/^[ \t]{#{indent}}/, '')
end
end
\ No newline at end of file
end
......@@ -33,6 +33,15 @@ def test_strip_heredoc_on_a_regular_indented_heredoc
EOS
end
def test_strip_heredoc_on_a_regular_indented_heredoc_with_blank_lines
assert_equal "foo\n bar\n\nbaz\n", <<-EOS.strip_heredoc
foo
bar
baz
EOS
end
def test_pluralize
SingularToPlural.each do |singular, plural|
assert_equal(plural, singular.pluralize)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册