Skip to content

Commit

Permalink
Hash compares
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed May 17, 2013
1 parent 4b12dbf commit cd9064e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
30 changes: 18 additions & 12 deletions lib-topaz/hash.rb
Expand Up @@ -60,21 +60,27 @@ def to_a
end

def ==(other)
if self.equal?(other)
return true
end
if !other.kind_of?(Hash)
return false
end
if self.size != other.size
return false
return true if self.equal?(other)
return false unless other.kind_of?(Hash)
return false unless self.size == other.size
Thread.current.recursion_guard(:hash_compare, self) do
self.each do |key, value|
return false unless other.has_key?(key) && value == other[key]
end
end
self.each do |key, value|
if !other.has_key?(key) || other[key] != value
return false
true
end

def eql?(other)
return true if self.equal?(other)
return false unless other.kind_of?(Hash)
return false unless self.size == other.size
Thread.current.recursion_guard(:hash_eql, self) do
self.each do |key, value|
return false unless other.has_key?(key) && value.eql?(other[key])
end
end
return true
true
end

def merge!(other, &block)
Expand Down
10 changes: 0 additions & 10 deletions spec/tags/core/hash/eql_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/tags/core/hash/equal_value_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/core/hash/merge_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/core/hash/reject_tags.txt

This file was deleted.

0 comments on commit cd9064e

Please sign in to comment.