Skip to content

Commit

Permalink
Improve value_object's #hash uniformity
Browse files Browse the repository at this point in the history
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
codesnik committed Dec 19, 2013
1 parent 6e7f6df commit 28c718e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/virtus/support/equalizer.rb
Expand Up @@ -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

Expand Down

0 comments on commit 28c718e

Please sign in to comment.