Sha256: 56965899438a60be86643124a1cd315488e2cb943bd59bc14352e0d6c3f230e7

Contents?: true

Size: 714 Bytes

Versions: 3

Compression:

Stored size: 714 Bytes

Contents

unless String.method_defined? :strip_margin
  class String
    # @return [String] The method strips the characters preceding a special
    # margin character. Useful for HEREDOCs and other multi-line strings.
    #
    # @example
    #
    #   code = <<-END.strip_margin('|')
    #     |def test
    #     |  some_method
    #     |  other_method
    #     |end
    #   END
    #
    #   #=> "def\n  some_method\n  \nother_method\nend"
    #
    # @note Extracted from the powerpack gem available under the MIT license
    #       and copyright (c) 2013 Bozhidar Batsov.
    #
    def strip_margin(margin_characters)
      margin = Regexp.quote(margin_characters)
      gsub(/^\s+#{margin}/, '')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
claide-0.7.0 lib/claide/mixins.rb
claide-0.6.1 lib/claide/mixins.rb
claide-0.6.0 lib/claide/mixins.rb