💎

Ruby: Hashの値からキーを取得する

2021/09/16に公開

keyメソッドを使えば良い
https://docs.ruby-lang.org/ja/latest/method/Hash/i/index.html

hash = { key1: 'val1', key2: 'val2' }

hash.key('val1')
# => :key1

hash.key('val2')
# => :key2

hash.key('val3')
# => nil

Discussion