Sha256: a836906fa31059fe1eedaf32b4dcdd186d6107919155132e35ddc489d5dcde9c

Contents?: true

Size: 625 Bytes

Versions: 49

Compression:

Stored size: 625 Bytes

Contents

# frozen_string_literal: true

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

49 entries across 49 versions & 8 rubygems

Version Path
activesupport-5.2.8.1 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.8 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.7.1 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.7 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.6.3 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.6.2 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.6.1 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.6 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.6 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.5 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.5 lib/active_support/core_ext/string/strip.rb
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/activesupport-5.2.4.1/lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.4 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.3 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.2 lib/active_support/core_ext/string/strip.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/activesupport-5.2.4.1/lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.1 lib/active_support/core_ext/string/strip.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4 lib/active_support/core_ext/string/strip.rb
activesupport-5.2.4.rc1 lib/active_support/core_ext/string/strip.rb