Sha256: 5efbd2c5290e194c00564a14f032c777a20da3aef70907b471edd1d2e055c261

Contents?: true

Size: 605 Bytes

Versions: 4

Compression:

Stored size: 605 Bytes

Contents

unless (RUBY_VERSION[0,3] == '1.9')

  class String

    # Does a string start with the given prefix.
    #
    #   "hello".starts_with?("he")    #=> true
    #   "hello".starts_with?("to")    #=> false
    #
    # CREDIT: Lucas Carlson, Blaine Cook

    def start_with?(prefix)
      self.index(prefix) == 0
    end

    # Does a string end with the given suffix?
    #
    #   "hello".ends_with?("lo")    #=> true
    #   "hello".ends_with?("to")    #=> false
    #
    # CREDIT: Lucas Carlson, Blaine Cook

    def end_with?(suffix)
      self.rindex(suffix) == size - suffix.size
    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
facets-2.6.0 lib/core/facets/string/start_with.rb
facets-2.5.0 lib/core/facets/string/start_with.rb
facets-2.5.1 lib/core/facets/string/start_with.rb
facets-2.5.2 lib/core/facets/string/start_with.rb