Sha256: e11110c6be9cdf503af6a2f12f2d546f52cba0b54c60022fa4f641b6d7374959

Contents?: true

Size: 614 Bytes

Versions: 14

Compression:

Stored size: 614 Bytes

Contents

class String
  # Strips indentation in heredocs.
  #
  # For example in
  #
  #   if options[:usage]
  #     puts <<-USAGE.strip_heredoc
  #       This command does such and such.
  #
  #       Supported options are:
  #         -h         This message
  #         ...
  #     USAGE
  #   end
  #
  # the user would see the usage message aligned against the left margin.
  #
  # Technically, it looks for the least indented line in the whole string, and removes
  # that amount of leading whitespace.
  def strip_heredoc
    indent = scan(/^[ \t]*(?=\S)/).min.to_s.size
    gsub(/^[ \t]{#{indent}}/, '')
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
aruba-0.11.0.pre lib/aruba/extensions/string/strip.rb
aruba-0.10.2 lib/aruba/extensions/string/strip.rb
aruba-0.10.1 lib/aruba/extensions/string/strip.rb
aruba-0.10.0 lib/aruba/extensions/string/strip.rb
aruba-0.10.0.pre2 lib/aruba/extensions/string/strip.rb
aruba-0.10.0.pre lib/aruba/extensions/string/strip.rb
aruba-0.9.0 lib/aruba/extensions/string/strip.rb
aruba-0.9.0.pre2 lib/aruba/extensions/string/strip.rb
aruba-0.9.0.pre lib/aruba/extensions/string/strip.rb
aruba-0.8.1 lib/aruba/extensions/string/strip.rb
aruba-0.8.0 lib/aruba/extensions/string/strip.rb
aruba-0.8.0.pre3 lib/aruba/extensions/string/strip.rb
aruba-0.8.0.pre2 lib/aruba/extensions/string/strip.rb
aruba-0.8.0.pre lib/aruba/extensions/string/strip.rb