Skip to content

Commit

Permalink
Update example to not use ^ as a hash function
Browse files Browse the repository at this point in the history
XOR is not a good hash function, and our example shouldn't give people the wrong idea. Better to just outsource to the built-in Hash function used by `Array`. It's more idiomatic, and will lead to less collisions.
  • Loading branch information
amomchilov authored Nov 26, 2024
1 parent d14cde4 commit d44d7af
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Email
end

def hash
self.class.hash ^ address.hash
[self.class, address].hash
end
end

Expand All @@ -144,7 +144,7 @@ class Phone
end

def hash
self.class.hash ^ country.hash ^ number.hash
[self.class, country, number].hash
end
end
```
Expand Down

0 comments on commit d44d7af

Please sign in to comment.