Module: Polyfill::V2_5::String

Defined in:
lib/polyfill/v2_5/string.rb

Instance Method Summary collapse

Instance Method Details

#casecmp(other_str) ⇒ Object



4
5
6
7
8
# File 'lib/polyfill/v2_5/string.rb', line 4

def casecmp(other_str)
  super
rescue TypeError
  nil
end

#casecmp?(other_str) ⇒ Boolean



10
11
12
13
14
# File 'lib/polyfill/v2_5/string.rb', line 10

def casecmp?(other_str)
  super
rescue TypeError
  nil
end

#delete_prefix(prefix) ⇒ Object



16
17
18
# File 'lib/polyfill/v2_5/string.rb', line 16

def delete_prefix(prefix)
  sub(/\A#{InternalUtils.to_str(prefix)}/, ''.freeze)
end

#delete_prefix!(prefix) ⇒ Object



20
21
22
23
24
# File 'lib/polyfill/v2_5/string.rb', line 20

def delete_prefix!(prefix)
  prev = dup
  current = sub!(/\A#{InternalUtils.to_str(prefix)}/, ''.freeze)
  prev == current ? nil : current
end

#delete_suffix(suffix) ⇒ Object



26
27
28
# File 'lib/polyfill/v2_5/string.rb', line 26

def delete_suffix(suffix)
  chomp(suffix)
end

#delete_suffix!(suffix) ⇒ Object



30
31
32
# File 'lib/polyfill/v2_5/string.rb', line 30

def delete_suffix!(suffix)
  chomp!(suffix)
end

#start_with?(*prefixes) ⇒ Boolean



34
35
36
37
38
39
40
# File 'lib/polyfill/v2_5/string.rb', line 34

def start_with?(*prefixes)
  super if prefixes.grep(Regexp).empty?

  prefixes.any? do |prefix|
    prefix.is_a?(Regexp) ? self[/\A#{prefix}/] : super(prefix)
  end
end