Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey/string.rb

Instance Method Summary collapse

Instance Method Details

#ends_with?(suffix) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/monkey/string.rb', line 8

def ends_with?(suffix)
  pattern = Regexp.new "#{Regexp.escape(suffix)}$"
  not ( pattern =~ self ).nil?
end

#starts_with?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
# File 'lib/monkey/string.rb', line 3

def starts_with?(prefix)
  pattern = Regexp.new "^#{Regexp.escape(prefix)}"
  not ( pattern =~ self ).nil?
end