Skip to content

Instantly share code, notes, and snippets.

@fcheung
Created April 8, 2015 12:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcheung/632cb0e63ad314c34521 to your computer and use it in GitHub Desktop.
Save fcheung/632cb0e63ad314c34521 to your computer and use it in GitHub Desktop.
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