Sha256: a3bf3b27f5d3b403d1eb3380ebbbdfa9ced9812bca52ab16a125afb0cafab610

Contents?: true

Size: 725 Bytes

Versions: 17

Compression:

Stored size: 725 Bytes

Contents

# Borrowed from activesupport, but without the :try method

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
    matches = scan(/^[ \t]*(?=\S)/).min
    indent = (matches.respond_to? :size) ? matches.size : 0
    gsub(/^[ \t]{#{indent}}/, '')
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
phrender-0.0.7 lib/string/strip.rb
phrender-0.0.6 lib/string/strip.rb
embork-0.0.13 lib/string/strip.rb
embork-0.0.12 lib/string/strip.rb
phrender-0.0.5 lib/string/strip.rb
embork-0.0.11 lib/string/strip.rb
embork-0.0.10 lib/string/strip.rb
embork-0.0.9 lib/string/strip.rb
embork-0.0.8 lib/string/strip.rb
phrender-0.0.4 lib/string/strip.rb
embork-0.0.7 lib/string/strip.rb
embork-0.0.6 lib/string/strip.rb
embork-0.0.5 lib/string/strip.rb
phrender-0.0.3 lib/string/strip.rb
phrender-0.0.2 lib/string/strip.rb
phrender-0.0.1 lib/string/strip.rb
embork-0.0.4 lib/string/strip.rb