aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-08-30 10:24:02 +0200
committerXavier Noria <fxn@hashref.com>2010-08-30 10:39:34 +0200
commitb422cda2ebfff4032f4c18271e96ad329c413dcc (patch)
tree0ce68f16f7d9b513cfcb0ba1ba56685c7aca849b /activesupport/lib/active_support
parent58d0e2c23c0c5578f23a4f4c639db5c0009b80c2 (diff)
downloadrails-b422cda2ebfff4032f4c18271e96ad329c413dcc.tar.gz
rails-b422cda2ebfff4032f4c18271e96ad329c413dcc.tar.bz2
rails-b422cda2ebfff4032f4c18271e96ad329c413dcc.zip
let String#strip_heredoc handle blank lines even if they are not indented
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/string/strip.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/strip.rb b/activesupport/lib/active_support/core_ext/string/strip.rb
index 84d279adbc..086c610976 100644
--- a/activesupport/lib/active_support/core_ext/string/strip.rb
+++ b/activesupport/lib/active_support/core_ext/string/strip.rb
@@ -1,3 +1,5 @@
+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