I have a hash of values from a database query:
a1 = {:a => 1, :b => 2 }
And another hash of values for a third party library:
b1 = {'a' => 1, 'b' => 2 }
I’d like to see if a1 has 'a' which I like to consider the equivalent of :a. How is that done? So I can check if there are any missing keys from b1 in a1.
What I want is to treat the key 'a' as the same as the key :a.
This will give you an array of (string) keys from
b1that are not present (as symbol keys) ina1:You can then do:
That’s assuming
b1always has only string keys, you’re only worried abouta1missing key/value pairs fromb1, and your goal is to insert the missing pairs intoa1(with symbol keys), all of which sound true from your question. If any of those assumptions are false, this should at least get you started.