Sha256: 231363e9918c31c3d6b8a59f583c1d553105aa333a62857c34a3d996f6faf8e0

Contents?: true

Size: 594 Bytes

Versions: 24

Compression:

Stored size: 594 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 non-empty line
  # in the whole string, and removes that amount of leading whitespace.
  def strip_heredoc
    gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".freeze)
  end
end

Version data entries

24 entries across 24 versions & 4 rubygems

Version Path
activesupport-5.1.7 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.7.rc1 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.6.2 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.6.1 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.6 lib/active_support/core_ext/string/strip.rb
tdiary-5.0.8 vendor/bundle/gems/activesupport-5.1.5/lib/active_support/core_ext/string/strip.rb
activesupport-5.1.5 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.5.rc1 lib/active_support/core_ext/string/strip.rb
pract6-0.1.0 .gem/ruby/2.3.0/gems/activesupport-5.1.4/lib/active_support/core_ext/string/strip.rb
activesupport-5.1.4 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.4.rc1 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.3 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.3.rc3 lib/active_support/core_ext/string/strip.rb
activerecord-update-0.1.0 lib/activerecord-update/core_ext/string/strip.rb
activesupport-5.1.3.rc2 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.3.rc1 lib/active_support/core_ext/string/strip.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.1.2/lib/active_support/core_ext/string/strip.rb
activesupport-5.1.2 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.2.rc1 lib/active_support/core_ext/string/strip.rb
activesupport-5.1.1 lib/active_support/core_ext/string/strip.rb