Module: Corefines::String::Unindent
- Defined in:
- lib/corefines/string.rb
Instance Method Summary collapse
-
#strip_heredoc ⇒ String
Alias for #unindent.
-
#unindent ⇒ String
Remove excessive indentation.
Instance Method Details
#strip_heredoc ⇒ String
Alias for #unindent.
498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/corefines/string.rb', line 498 module Unindent refine ::String do def unindent leading_space = scan(/^[ \t]*(?=\S)/).min indent = leading_space ? leading_space.size : 0 gsub /^[ \t]{#{indent}}/, '' end alias_method :strip_heredoc, :unindent end end |
#unindent ⇒ String
Remove excessive indentation. Useful for multi-line strings embeded in already indented code.
Technically, it looks for the least indented line in the whole string (blank lines are ignored) and removes that amount of leading whitespace.
498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/corefines/string.rb', line 498 module Unindent refine ::String do def unindent leading_space = scan(/^[ \t]*(?=\S)/).min indent = leading_space ? leading_space.size : 0 gsub /^[ \t]{#{indent}}/, '' end alias_method :strip_heredoc, :unindent end end |