Reputation: 16195
In Ruby, one can find which keys exist in both a hash and an array using the following
(hash.keys & array_of_keys)
What operator do I need to use in order to find keys in the hash that do not exist in the array?
Upvotes: 0
Views: 41
Reputation: 2483
Simply hash.keys - array_of_keys
.
hash = {a: 'a', b: 'b', c: 'c'}
array_of_keys = [:a, :c]
hash.keys - array_of_keys
# => [:b]
Upvotes: 4