Unfortunately this is mathematically impossible to define a valid hash function in this case.
Let a, b be two elements with equal positions, and different names. According to eql?
definition, this implies that h(a) == h(b)
. Since this is true for any names values, the hash function is to be independent on name attribute, which is however in contradiction with the second check. Hence there is no hash function for this eql?
definition. Sorry. :(
Update:
As noted by toro2k - your equality definition is not transitive. In general if a == b and b == c, it is required that a == c. According to your eql?
function:
{pos_x: 1, pos_y: 1, name: 'a'} == {pos_x: 1, pos_y: 1, name: 'b'}
{pos_x: 1, pos_y: 1, name: 'b'} == {pos_x: 2, pos_y: 2, name: 'b'}
but
{pos_x: 1, pos_y: 1, name: 'a'} != {pos_x: 2, pos_y: 2, name: 'b'}
That's the root of your problem here.