Ruby 在哈希中查找数组中不存在的键
在Ruby中,可以使用以下方法找到哈希和数组中都存在哪些键Ruby 在哈希中查找数组中不存在的键,ruby,arrays,hash,logical-operators,Ruby,Arrays,Hash,Logical Operators,在Ruby中,可以使用以下方法找到哈希和数组中都存在哪些键 (hash.keys & array_of_keys) 我需要使用什么运算符才能在哈希中查找数组中不存在的键?使用 使用 简单地hash.keys-数组\u的\u键 hash = {a: 'a', b: 'b', c: 'c'} array_of_keys = [:a, :c] hash.keys - array_of_keys # => [:b] 简单地hash.keys-数组\u的\u键 hash = {a: '
(hash.keys & array_of_keys)
我需要使用什么运算符才能在哈希中查找数组中不存在的键?使用
使用
简单地
hash.keys-数组\u的\u键
hash = {a: 'a', b: 'b', c: 'c'}
array_of_keys = [:a, :c]
hash.keys - array_of_keys
# => [:b]
简单地
hash.keys-数组\u的\u键
hash = {a: 'a', b: 'b', c: 'c'}
array_of_keys = [:a, :c]
hash.keys - array_of_keys
# => [:b]