diff options
author | Joost Lubach <joost@yoazt.com> | 2013-08-07 15:18:30 +0200 |
---|---|---|
committer | Joost Lubach <joost@yoazt.com> | 2013-08-07 16:46:30 +0200 |
commit | 369a107c8e30a15d03cb2e85242bc604fe7a02a3 (patch) | |
tree | 54542123900dfe48790f8043f474e3f8b4763eb4 /activesupport/lib/active_support | |
parent | 4343e2dda25222d3586835bb25009e1a490cda8f (diff) | |
download | rails-369a107c8e30a15d03cb2e85242bc604fe7a02a3.tar.gz rails-369a107c8e30a15d03cb2e85242bc604fe7a02a3.tar.bz2 rails-369a107c8e30a15d03cb2e85242bc604fe7a02a3.zip |
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
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/duration.rb | 6 |
1 files changed, 6 insertions, 0 deletions
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 |