Sha256: f5136eaaa458ec8fa1a6b76e6f905f2ae5b2fb986fe6d0dfe5befe0e1b667706

Contents?: true

Size: 573 Bytes

Versions: 11

Compression:

Stored size: 573 Bytes

Contents

unless String.method_defined? :remove_prefix
  class String
    # Removes a prefix in a string.
    #
    # @return [String] a new string without the prefix.
    #
    # @example
    #   'Ladies Night'.remove_prefix('Ladies ') #=> 'Night'
    def remove_prefix(pattern)
      dup.remove_prefix!(pattern)
    end

    # Removes a prefix in a string.
    #
    # @return [String] the string without the prefix.
    #
    # @example
    #   'Ladies Night'.remove_prefix!('Ladies ') #=> 'Night'
    def remove_prefix!(pattern)
      gsub!(/\A#{pattern}/, '')
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_prefix.rb
powerpack-0.1.1 lib/powerpack/string/remove_prefix.rb
powerpack-0.1.0 lib/powerpack/string/remove_prefix.rb