Sha256: 447c8e4afd521ee0e4dd33e4bb111edcef6ef46413d1f0d358f2e442aed52e83

Contents?: true

Size: 573 Bytes

Versions: 11

Compression:

Stored size: 573 Bytes

Contents

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

    # Removes a suffix in a string.
    #
    # @return [String] the string without the suffix.
    #
    # @example
    #   'Ladies Night'.remove_suffix!(' Night') #=> 'Ladies'
    def remove_suffix!(pattern)
      gsub!(/#{pattern}\z/, '')
    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_suffix.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/powerpack-0.1.1/lib/powerpack/string/remove_suffix.rb
powerpack-0.1.1 lib/powerpack/string/remove_suffix.rb
powerpack-0.1.0 lib/powerpack/string/remove_suffix.rb