deriving :: DeriveEqual :: defaultinit
# Implementation of `==` and `hash` for `Derivable` objects.
#
# The implementations just call `==` and `hash` on `derive_to_map`.
#
# ~~~
# class A
# auto_derive
# super DeriveEqual
# var an_int: Int
# var a_string: String
# end
#
# var a = new A(5, "five")
# var b = new A(5, "five")
# var c = new A(6, "six")
# assert a == b
# assert a.hash == b.hash
# assert a != c
# ~~~
#
# Warning: the method may go in an infinite recursion if there is a circuit in
# the implementation of `==` or `hash`.
interface DeriveEqual
super Derivable
redef fun ==(other) do
if not other isa Derivable then return false
return derive_to_map == other.derive_to_map
end
redef fun hash do
return derive_to_map.hash
end
end
lib/deriving/deriving.nit:86,1--117,3