Introduce a new static method `Object.same(obj1, obj2)` that exposes the VM's built-in equality semantics (`wrenValuesEqual`) directly, bypassing any user-defined `==` overrides. This required creating a dedicated metaclass for Object (subclass of Class) to host the static method without polluting every class with a `same` method. The implementation wires up a new `Object metaclass` in the core initialization sequence, adjusts the class hierarchy setup order, and adds comprehensive tests covering value types, identity comparison, and verification that `Object.same` ignores custom `==` operators.
1.1 KiB
^title Object Class ^category core
Static Methods
same(obj1, obj2)
Returns true if obj1 and obj2 are the same. For value
types, this returns true if the objects have equivalent
state. In other words, numbers, strings, booleans, and ranges compare by value.
For all other objects, this returns true only if obj1 and obj2 refer to
the exact same object in memory.
This is similar to the built in == operator in Object except that this cannot
be overriden. It allows you to reliably access the built-in equality semantics
even on user-defined classes.
Methods
! operator
Returns false, since most objects are considered true.
==(other) and !=(other) operators
Compares two objects using built-in equality. This compares value types by value, and all other objects are compared by identity—two objects are equal only if they are the exact same object.
toString
A default string representation of the object.
type
The Class of the object.