Permalink
Browse files

Merge pull request #16560 from robin850/rbx-duration-eql

Define the Duration#instance_of? method
  • Loading branch information...
2 parents f020f30 + eb73d7d commit 9b61a7eda929fcc2e2b0cd34e27d0fceafa7c389 @rafaelfranca rafaelfranca committed Aug 22, 2014
@@ -1,6 +1,11 @@
+* Add the `Duration#instance_of?` method that was previously delegated to the
+ internal `value` attribute.
+
+ *Robin Dupret*
+
* Fix rounding errors with #travel_to by resetting the usec on any passed time to zero, so we only travel
with per-second precision, not anything deeper than that.
-
+
*DHH*
* Fix ActiveSupport::TestCase not to order users' test cases by default.
@@ -35,10 +35,14 @@ def -@ #:nodoc:
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 <tt>other == value</tt>.
def ==(other)
@@ -41,6 +41,11 @@ def test_eql
assert !1.eql?(1.second)
end
+ def test_instance_of
+ assert !1.minute.instance_of?(Fixnum)
+ assert !2.days.instance_of?(Fixnum)
+ end
+
def test_inspect
assert_equal '0 seconds', 0.seconds.inspect
assert_equal '1 month', 1.month.inspect

0 comments on commit 9b61a7e

Please sign in to comment.