From 398b611fe35af26d3dbbf3679ac21bedfc8f14ff Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Mon, 18 Jan 2021 14:32:26 +0100 Subject: [PATCH] Add suggestion from code review --- src/hash.cr | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hash.cr b/src/hash.cr index 77b21cac8209..f72ab00beffb 100644 --- a/src/hash.cr +++ b/src/hash.cr @@ -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_key = other.fetch(key) { return false } + other_key == 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_key = other.fetch(key) { return false } + other_key == value + end end # Returns `true` if *other* is a subset of `self`.