Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
if Rails::VERSION::MAJOR > 4
raise "This patch is obsolete and should be removed"
end
class Time
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
alias_method :<=>, :compare_with_coercion
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment