to_s
for Derivable
objects.The implementation uses to_s
for each value of attributes_to_map
.
class A
auto_derive
super DeriveToS
var an_int: Int
var a_string: String
end
var a = new A(5, "five")
assert a.to_s == "an_int:5; a_string:five"
Warning: the method may go in an infinite recursion if there is a circuit in
the implementation of to_s
.
deriving :: DeriveToS :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
deriving :: Derivable :: defaultinit
deriving :: DeriveToS :: 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 `to_s` for `Derivable` objects.
#
# The implementation uses `to_s` for each value of `attributes_to_map`.
#
# ~~~
# class A
# auto_derive
# super DeriveToS
# var an_int: Int
# var a_string: String
# end
#
# var a = new A(5, "five")
# assert a.to_s == "an_int:5; a_string:five"
# ~~~
#
# Warning: the method may go in an infinite recursion if there is a circuit in
# the implementation of `to_s`.
interface DeriveToS
super Derivable
redef fun to_s do return derive_to_map.join("; ", ":")
end
lib/deriving/deriving.nit:63,1--84,3