Skip to content

Commit

Permalink
Add suggestion from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija committed Jan 18, 2021
1 parent 465e548 commit 5d8c8c6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hash.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1750,13 +1750,19 @@ class Hash(K, V)
# Returns `true` if `self` is a subset of *other*.
def proper_subset_of?(other : Hash)
return false if other.size <= size
all? { |key, value| other[key]? == value }
all? do |key, value|
other_value = other.fetch(key) { return false }
other_value == value
end
end

# Returns `true` if `self` is a subset of *other* or equals to *other*.
def subset_of?(other : Hash)
return false if other.size < size
all? { |key, value| other[key]? == value }
all? do |key, value|
other_value = other.fetch(key) { return false }
other_value == value
end
end

# Returns `true` if *other* is a subset of `self`.
Expand Down

0 comments on commit 5d8c8c6

Please sign in to comment.