==
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
.
deriving :: DeriveEqual :: defaultinit
deriving $ DeriveEqual :: SELF
Type of this instance, automatically specialized in every classcore :: Object :: class_factory
Implementation used byget_class
to create the specific class.
deriving :: Derivable :: defaultinit
deriving :: DeriveEqual :: defaultinit
core :: Object :: defaultinit
deriving :: Derivable :: derive_to_map
Returns a map that loosely represents the objectself
.
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# 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