Module ActiveSupport::CoreExtensions::String::StartsEndsWith
In: vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb

Additional string tests.

Methods

Public Class methods

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb, line 6
 6:         def self.append_features(base)
 7:           if '1.8.7 and up'.respond_to?(:start_with?)
 8:             base.class_eval do
 9:               alias_method :starts_with?, :start_with?
10:               alias_method :ends_with?, :end_with?
11:             end
12:           else
13:             super
14:             base.class_eval do
15:               alias_method :start_with?, :starts_with?
16:               alias_method :end_with?, :ends_with?
17:             end
18:           end
19:         end

Public Instance methods

Does the string end with the specified suffix?

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb, line 28
28:         def ends_with?(suffix)
29:           suffix = suffix.to_s
30:           self[-suffix.length, suffix.length] == suffix      
31:         end

Does the string start with the specified prefix?

[Source]

    # File vendor/rails/activesupport/lib/active_support/core_ext/string/starts_ends_with.rb, line 22
22:         def starts_with?(prefix)
23:           prefix = prefix.to_s
24:           self[0, prefix.length] == prefix
25:         end

[Validate]