From 369a107c8e30a15d03cb2e85242bc604fe7a02a3 Mon Sep 17 00:00:00 2001 From: Joost Lubach Date: Wed, 7 Aug 2013 15:18:30 +0200 Subject: Added method `#eql?` to `ActiveSupport::Duration`, in addition to `#==`. Currently, the following returns `false`, contrary to expectation: 1.minute.eql?(1.minute) Adding method `#eql?` will make this behave like expected. Method `#eql?` is just a bit stricter than `#==`, as it checks whether the argument is also a uration. Their parts may be different though. 1.minute.eql?(60.seconds) # => true 1.minute.eql?(60) # => false --- activesupport/lib/active_support/duration.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 2cb1f408b6..7cd27717f9 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -49,6 +49,12 @@ module ActiveSupport end end + # Returns +true+ if +other+ is also a Duration instance, which has the + # same parts as this one. + def eql?(other) + Duration === other && other.value.eql?(value) + end + def self.===(other) #:nodoc: other.is_a?(Duration) rescue ::NoMethodError -- cgit v1.2.3