Sha256: be01d8c975412c31485b4d61a06432a346591f0c7e8d68e0bb84660b7ac17a89

Contents?: true

Size: 620 Bytes

Versions: 14

Compression:

Stored size: 620 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.try(:size) || 0
    gsub(/^[ \t]{#{indent}}/, '')
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
motion-support-1.2.1 motion/core_ext/string/strip.rb
motion-support-1.1.1 motion/core_ext/string/strip.rb
motion-support-1.2.0 motion/core_ext/string/strip.rb
motion-support-1.1.0 motion/core_ext/string/strip.rb
motion-support-1.0.0 motion/core_ext/string/strip.rb
motion-support-0.3.0 motion/core_ext/string/strip.rb
motion_blender-support-0.2.8 motion/core_ext/string/strip.rb
motion_blender-support-0.2.7 motion/core_ext/string/strip.rb
motion-support-0.2.6 motion/core_ext/string/strip.rb
motion-support-0.2.5 motion/core_ext/string/strip.rb
motion-support-0.2.4 motion/core_ext/string/strip.rb
motion-support-0.2.3 motion/core_ext/string/strip.rb
motion-support-0.2.2 motion/core_ext/string/strip.rb
motion-support-0.2.0 motion/core_ext/string/strip.rb