Sha256: a108a880d4fd98fd7ce2dd40c0cb84a0521c8e67ee56024436d071df6c273106

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

class String

  # Removes all occurrences of a pattern in a string.
  #
  # Returns a new [String] with all occurrences of the pattern removed.
  def remove(pattern)
    gsub(pattern, '')
  end

  # Removes all occurrences of a pattern in a string.
  #
  # Returns the [String] with all occurrences of the pattern removed.
  def remove!(pattern)
    gsub!(pattern, '')
  end

  # Removes occurances of a string or regexp. This is an operator
  # form for the #remove method.
  #
  #   ("HELLO HELLO" - "LL")    #=> "HEO HEO"
  #   ("HELLO PERL" - /L\S/)    #=> "HEO PERL"
  #
  # Returns a new [String] with all pattern matches removed.
  #
  # CREDIT: Benjamin David Oakes
  def -(pattern)
    gsub(pattern, '')
  end

end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/string/remove.rb
facets-3.1.0 lib/core/facets/string/remove.rb
facets-3.0.0 lib/core/facets/string/remove.rb