Created
February 13, 2013 16:14
-
-
Save drewblas/4945697 to your computer and use it in GitHub Desktop.
Revisions
-
drewblas created this gist
Feb 13, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ # ============================= # Test case showing what we expect to happen a1 = 'z' b1 = 'z' a = [a1] b = [b1] a1 == b1 # true a1.eql? b1 # true a1.equal? b1 # false different object_ids, as expected a.eql? b # true a - b # = [] b - a # = [] #EVERYTHING IS GOOD HERE. DIFFERENT OBJECT_IDS BUT EQUAL OBJECTS SUBTRACT OUT OF ARRAY # ============================= # Simple class that should act the same as above class MyObject attr_accessor :str def initialize(str) @str = str end def eql?(other) @str.eql? other.str end def ==(other) @str == other.str end end # ============================= # Test case that is messed up! object1 = MyObject.new('z') object2 = MyObject.new('z') a = [object1] b = [object2] object1 == object2 # true object1.eql? object2 # true object1.equal? object2 # false different object_ids, as expected a.eql? b # true a - b # = [object1] b - a # = [object2] # WHY ARE THESE NOT EMPTY?!?!