mirror of
https://github.com/github/rails.git
synced 2026-01-29 08:18:03 -05:00
Ruby 1.8.7 compat: String#start_with? and #end_with?
This commit is contained in:
@@ -2,7 +2,7 @@ require 'active_support/core_ext/string/inflections'
|
||||
require 'active_support/core_ext/string/conversions'
|
||||
require 'active_support/core_ext/string/access'
|
||||
require 'active_support/core_ext/string/starts_ends_with'
|
||||
require 'active_support/core_ext/string/iterators' unless 'test'.respond_to?(:each_char)
|
||||
require 'active_support/core_ext/string/iterators'
|
||||
require 'active_support/core_ext/string/unicode'
|
||||
require 'active_support/core_ext/string/xchar'
|
||||
require 'active_support/core_ext/string/filters'
|
||||
@@ -12,14 +12,7 @@ class String #:nodoc:
|
||||
include ActiveSupport::CoreExtensions::String::Conversions
|
||||
include ActiveSupport::CoreExtensions::String::Filters
|
||||
include ActiveSupport::CoreExtensions::String::Inflections
|
||||
if RUBY_VERSION < '1.9'
|
||||
include ActiveSupport::CoreExtensions::String::StartsEndsWith
|
||||
else
|
||||
alias starts_with? start_with?
|
||||
alias ends_with? end_with?
|
||||
end
|
||||
if defined? ActiveSupport::CoreExtensions::String::Iterators
|
||||
include ActiveSupport::CoreExtensions::String::Iterators
|
||||
end
|
||||
include ActiveSupport::CoreExtensions::String::StartsEndsWith
|
||||
include ActiveSupport::CoreExtensions::String::Iterators
|
||||
include ActiveSupport::CoreExtensions::String::Unicode
|
||||
end
|
||||
|
||||
@@ -5,6 +5,10 @@ module ActiveSupport #:nodoc:
|
||||
module String #:nodoc:
|
||||
# Custom string iterators
|
||||
module Iterators
|
||||
def self.append_features(base)
|
||||
super unless '1.9'.respond_to?(:each_char)
|
||||
end
|
||||
|
||||
# Yields a single-character string for each character in the string.
|
||||
# When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
|
||||
def each_char
|
||||
|
||||
@@ -3,10 +3,18 @@ module ActiveSupport #:nodoc:
|
||||
module String #:nodoc:
|
||||
# Additional string tests.
|
||||
module StartsEndsWith
|
||||
def self.included(base)
|
||||
base.class_eval do
|
||||
alias_method :start_with?, :starts_with?
|
||||
alias_method :end_with?, :ends_with?
|
||||
def self.append_features(base)
|
||||
if '1.8.7 and up'.respond_to?(:start_with?)
|
||||
base.class_eval do
|
||||
alias_method :starts_with?, :start_with?
|
||||
alias_method :ends_with?, :end_with?
|
||||
end
|
||||
else
|
||||
super
|
||||
base.class_eval do
|
||||
alias_method :start_with?, :starts_with?
|
||||
alias_method :end_with?, :ends_with?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user