Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 在哈希中查找数组中不存在的键_Ruby_Arrays_Hash_Logical Operators - Fatal编程技术网

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: '

在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: 'a', b: 'b', c: 'c'}
array_of_keys = [:a, :c]

hash.keys - array_of_keys
# => [:b]