🖥

Ruby | Find keys common to multiple hashes

に公開

keys and & .

Example 1

Next, if both has b: and c: keys.

 { a: nil, b: nil, c: nil }.keys & { b: nil, c: nil, d: nil }.keys # => [:b, :c] 

Example 2

It can also be used for three or more hashes.

Next, if every hash has a key of c: .

 { a: nil, b: nil, c: nil }.keys & { b: nil, c: nil, d: nil }.keys & { c: nil, d: nil, e: nil}.keys # => [:c] 

environment

  • ruby 2.3.0

Original by

Ruby | 複数のハッシュに共通するキーを調べる

About

About this translattion

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ

Twitter

https://twitter.com/YumaInaura

公開日時

2019-04-16

Discussion