Given that Time
objects cannot be compared with Fixnum
without explicit casting:
0 <= Time.now # => ArgumentError: comparison of Fixnum with Time failed
Time.now <= 10000000000 # => ArgumentError: comparison of Time with 10000000000 failed
and what the documentation for Range#cover?
says,
cover?(obj)
→true
orfalse
Returns
true
ifobj
is between thebegin
andend
of the range.This tests
begin <= obj <= end
whenexclude_end?
isfalse
andbegin <= obj < end
whenexclude_end?
istrue
.
I expect:
(0...10000000000).cover?(Time.now) # => false
to raise an exception rather than silently return false
. Why doesn't it raise an exception?
It is understandable that, with explicit casting, the comparison works:
(0...10000000000).cover?(Time.now.to_i) # => true