(Moved from comments above)
You are probably not overriding #hash and #eql? in your SampleClass. Which you need to do in order for data structures like Hashes and Sets to work properly.
Programming languages have a notion of equality of objects that usually consists of some sort of equality function and a hash function (eql? and hash in Ruby). The language uses the equality function to determine if two Objects are equal. The hash function computes a hash (unique value) for each object that is used by certain data structures such as sets and hash tables. The important piece is that if two Objects are equal (in terms of eql?) they must have the same hash value, otherwise the hash tables and sets will not function properly.
My Ruby is a little rusty, but it might look something like this for your SampleClass:
class SampleClass
...
def eql? other
other.instance_of?(self.class)
&& @id == other.id
&& @name == other.name
end
# delegate to hash function of whatever primitive @id and @name are
# probably Fixnum and String?
# Uses two prime numbers, adapted from Effective Java by Joshua Bloch
def hash
p, q = 17, 37
p = q * @id.hash
p = q * @name.hash
end
...
end