public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
rails / activesupport / lib / active_support / core_ext / string / starts_ends_with.rb
100644 19 lines (16 sloc) 0.484 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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