From 5d8c8c662ea99937e1945ddc539dedc2b3a8285f 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..6c40631b061e 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_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`.