Use equal? to check the references : equal « Class « Ruby






Use equal? to check the references


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
b.equal?(c)      # true: b and c refer to the same object

 








Related examples in the same category

1.Same value but different reference
2.== and equal" are different