Permalink
Browse files

Improve value_object's #hash uniformity

Array#hash is designed to be uniform, unlike reduce(:^).hash

class Point
  include Virtus.value_object
  values do
     attribute :x, Integer
     attribute :y, Integer
  end
end

Point.new(x: 1, y: 1).hash == Point.new.hash # was true
Point.new(x: 1).hash == Point.new(y: 1).hash # was true
  • Loading branch information...
1 parent 6e7f6df commit 28c718e102062ce3ebb280fc81833f31776a028d @codesnik codesnik committed Dec 19, 2013
Showing with 1 addition and 1 deletion.
  1. +1 −1 lib/virtus/support/equalizer.rb
@@ -65,7 +65,7 @@ def define_cmp_method
def define_hash_method
keys = @keys
define_method(:hash) do
- keys.map { |key| send(key).hash }.reduce(self.class.hash, :^)
+ keys.map { |key| send(key) }.push(self.class).hash
end
end

0 comments on commit 28c718e

Please sign in to comment.