Determining if two objects are "equal"

Mithran

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
404
Reaction score
217
First Language
English
Primarily Uses
@another_fen - Yes and no. Based on my tests, for objects without a custom marshal_dump defined, it appears the order of serialization is based on the creation order of the instance variables the very first time they were created within any given class during this run. This also applies to objects reconstituted with Marshal.load() - if this was the first time certain instance variables were created, they will be "remembered" by Marshal for this run. Therefore, even if you load two objects from files from runtimes that had a different instance variable creation order (and therefore a different serialization order), the string returned by Marshal.dump() for both objects will be the same if both original objects had the same attributes, regardless of order.


If you want things to be serialized and loaded in a specific, non changing order, you can define your own marshal_dump and marshal_load instance methods, but this shouldn't be necessary unless you need Marshal support for a class that doesn't have it by default or you need to analyze the byte stream yourself.


@shaz


It should be also be for this method that a non-existent instance variable and nil value for a variable have two different serialization values, so omitting variables will cause a different serialization output even though the "value" of a non initialized instance variable is still nil. But since you said you weren't too concerned with lazy evaluation, this probably won't be an issue either.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I've covered the case where classes are made up of attributes, and some of those are smaller classes. Not being able to do a == b is what prompted this whole post in the first place. I THINK I've got it sorted in most cases - preliminary testing returns good results.


I've also catered for the possibility of nil values and of attributes that exist in one but not the other.


I had written up an overview of what I've done so far and am currently testing, but when I posted, I somehow lost it when the screen refreshed. I don't have time to write it up again. The weekend will give me another opportunity :)
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,575
Latest member
akekaphol101
Top