aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
blob: f65bb8f75be46fa492306835cd8c5d5b2b73742f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class String
  unless '1.8.7 and up'.respond_to?(:start_with?)
    # Does the string start with the specified +prefix+?
    def start_with?(prefix)
      prefix = prefix.to_s
      self[0, prefix.length] == prefix
    end

    # Does the string end with the specified +suffix+?
    def end_with?(suffix)
      suffix = suffix.to_s
      self[-suffix.length, suffix.length] == suffix
    end
  end

  alias_method :starts_with?, :start_with?
  alias_method :ends_with?, :end_with?
end