I'm looking for a better way to do
if hash.key? :a && hash.key? :b && hash.key? :c && hash.key? :d
preferably something like
hash.includes_keys? [ :a, :b, :c, :d ]
I came up with
hash.keys & [:a, :b, :c, :d] == [:a, :b, :c, :d]
but I dont like having to add the array twice though
Ruby | Hash key() functionHash#key() is a Hash class method which gives the key value corresponding to the value. If value doesn't exist then return nil.
%i[a b c d].all? {|s| hash.key? s}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With