Same value but different reference : equal « Class « Ruby






Same value but different reference



a = "Ruby"       # One reference to one String object
b = c = "Ruby"   # Two references to another String object

a.equal?(b)      # false: a and b are different objects

a.object_id == b.object_id   # Works like a.equal?(b)

 








Related examples in the same category

1.Use equal? to check the references
2.== and equal" are different