From 5aeb3cd3ac88a6a16b6d573e4bbad846938fd5a7 Mon Sep 17 00:00:00 2001 From: Emily Dobervich Date: Tue, 8 Apr 2014 16:24:35 -0700 Subject: Fixed problem where `1.day.eql?(1.day)` is false This fixes: 1.second.eql?(1.second) #=> false The new `eql?` requires that `other` is an `ActiveSupport::Duration`. This requirement makes `ActiveSupport::Duration`'s behavior consistent with other numeric types in Ruby. 1.eql?(1.0) #=> false 1.0.eql?(1) #=> false 1.second.eql?(1) #=> false (was true) 1.eql?(1.second) #=> false { 1 => "foo", 1.0 => "bar" } #=> { 1 => "foo", 1.0 => "bar" } { 1 => "foo", 1.second => "bar" } # now => { 1 => "foo", 1.second => "bar" } # was => { 1 => "bar" } And though the behavior here hasn't changed, for reference: 1 == 1.0 #=> true 1.0 == 1 #=> true 1 == 1.second #=> true 1.second == 1 #=> true --- activesupport/lib/active_support/duration.rb | 4 ++++ 1 file changed, 4 insertions(+) (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 7df4857c25..09eb732ef7 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -49,6 +49,10 @@ module ActiveSupport end end + def eql?(other) + other.is_a?(Duration) && self == other + end + def self.===(other) #:nodoc: other.is_a?(Duration) rescue ::NoMethodError -- cgit v1.2.3