Sha256: 8adefe9b80417e0ea92ef33d674514c1dbef5c66d74bd282d70af1adedbc4e95

Contents?: true

Size: 547 Bytes

Versions: 2

Compression:

Stored size: 547 Bytes

Contents

unless String.method_defined? :strip_margin
  class 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"
    def strip_margin(margin_character)
      margin = '\\' + margin_character
      gsub(/^\s+#{margin}/, '')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
powerpack-0.0.4 lib/powerpack/string/strip_margin.rb
powerpack-0.0.3 lib/powerpack/string/strip_margin.rb