From eb73d7dafa343507a60f765c43c748d6987ec652 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sun, 17 Aug 2014 16:31:00 +0200 Subject: Define the Duration#instance_of? method Since Duration is extending from ProxyObject which extends itself from BasicObject, the Duration object doesn't respond to the #instance_of? method. Thus, the #method_missing hook get triggered, delegating the method to its `value` attribute. However, Rubinius' #eql? definition relies on #instance_of?, thus this will equal to true with a Fixnum (since its `value` attribute is a Fixnum) while it should not. The previous behavior was wrong anyway, no matter the implementation. --- activesupport/lib/active_support/duration.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/duration.rb') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 0ae641d05b..084d13a9e3 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -35,10 +35,14 @@ module ActiveSupport end def is_a?(klass) #:nodoc: - Duration == klass || value.is_a?(klass) + instance_of?(klass) || value.is_a?(klass) end alias :kind_of? :is_a? + def instance_of?(klass) # :nodoc: + Duration == klass + end + # Returns +true+ if +other+ is also a Duration instance with the # same +value+, or if other == value. def ==(other) -- cgit v1.2.3 From d5578cd17716fbda11ec37ce7489699d191878a3 Mon Sep 17 00:00:00 2001 From: Robin Dupret Date: Sat, 23 Aug 2014 13:09:41 +0200 Subject: Follow-up to #16560 For the sake of backward-compatibility, we need to make #instance_of? return true for Fixnum. On the other hand, the method should still give true for ActiveSupport::Duration itself which was not the case before. --- activesupport/lib/active_support/duration.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/duration.rb') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 084d13a9e3..1a6c02a39b 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -35,12 +35,12 @@ module ActiveSupport end def is_a?(klass) #:nodoc: - instance_of?(klass) || value.is_a?(klass) + Duration == klass || value.is_a?(klass) end alias :kind_of? :is_a? def instance_of?(klass) # :nodoc: - Duration == klass + Duration == klass || value.instance_of?(klass) end # Returns +true+ if +other+ is also a Duration instance with the -- cgit v1.2.3