#== implementation

So I discovered that MyClass.new(1) !== MyClass.new(1) as Reference is the default parent of classes.

Which is indeed a sensible default.


def ==(other : self)
  prop1 == other.prop1 && prop2 == other.prop2 && prop3 == other.prop3

doesn’t feel very elegant, and get pretty annoying with a lot of instance variables (as one might end up with when deserializing JSON from some API).

Is there a more elegant way to do it?

There is def_equals and def_equals_and_hash as well as def_hash.


Oh, but of course there’s a macro. Much nicer.

1 Like