If I know there is only one key/value pair in a hash, is there a direct way to retrieve either the key or the value directly without having to get all the keys or values?
here is a simple example:
hsh1 = {a: 1}
hsh2 = {a: 2}
hsh1.keys # => [:a]
hsh2.values # => [2]
hsh1.values + hsh2.values # => [1,2]
Is there a way to get this instead?
1 + 2 # => 3
hsh1 = {a: 1}
hsh2 = {b: 2}
hsh1.values.first + hsh2.values.first # => 3
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