mirror of
https://github.com/github/rails.git
synced 2026-01-28 15:58:03 -05:00
Ruby 1.8.7 compat: TimeWithZone# and Chars#respond_to? pass along the include_private argument
This commit is contained in:
@@ -40,13 +40,15 @@ module ActiveSupport::Multibyte #:nodoc:
|
||||
# core dumps. Don't go there.
|
||||
@string
|
||||
end
|
||||
|
||||
|
||||
# Make duck-typing with String possible
|
||||
def respond_to?(method)
|
||||
super || @string.respond_to?(method) || handler.respond_to?(method) ||
|
||||
(method.to_s =~ /(.*)!/ && handler.respond_to?($1)) || false
|
||||
def respond_to?(method, include_priv = false)
|
||||
super || @string.respond_to?(method, include_priv) ||
|
||||
handler.respond_to?(method, include_priv) ||
|
||||
(method.to_s =~ /(.*)!/ && handler.respond_to?($1, include_priv)) ||
|
||||
false
|
||||
end
|
||||
|
||||
|
||||
# Create a new Chars instance.
|
||||
def initialize(str)
|
||||
@string = str.respond_to?(:string) ? str.string : str
|
||||
|
||||
@@ -248,14 +248,14 @@ module ActiveSupport
|
||||
def marshal_load(variables)
|
||||
initialize(variables[0], ::Time.send!(:get_zone, variables[1]), variables[2])
|
||||
end
|
||||
|
||||
|
||||
# Ensure proxy class responds to all methods that underlying time instance responds to.
|
||||
def respond_to?(sym)
|
||||
def respond_to?(sym, include_priv = false)
|
||||
# consistently respond false to acts_like?(:date), regardless of whether #time is a Time or DateTime
|
||||
return false if sym.to_s == 'acts_like_date?'
|
||||
super || time.respond_to?(sym)
|
||||
super || time.respond_to?(sym, include_priv)
|
||||
end
|
||||
|
||||
|
||||
# Send the missing method to +time+ instance, and wrap result in a new TimeWithZone with the existing +time_zone+.
|
||||
def method_missing(sym, *args, &block)
|
||||
result = time.__send__(sym, *args, &block)
|
||||
|
||||
Reference in New Issue
Block a user