instance method
compare_with_coercion
Ruby on Rails 7.1.6
Since v3.0.20Signature
compare_with_coercion(other)
Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances can be chronologically compared with a Time
Parameters
-
otherreq
Source
# File activesupport/lib/active_support/core_ext/time/calculations.rb, line 332
def compare_with_coercion(other)
# we're avoiding Time#to_datetime and Time#to_time because they're expensive
if other.class == Time
compare_without_coercion(other)
elsif other.is_a?(Time)
compare_without_coercion(other.to_time)
else
to_datetime <=> other
end
end
Defined in activesupport/lib/active_support/core_ext/time/calculations.rb line 332
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in Time