I have:
arr = ['test', 'testing', 'test123']
ht = {"test": "abc", "water": "wet", "testing": "fun"}
How can I select the values in ht whose key matches arr?
ht_new = ht.select {|hashes| arr.include? hashes}
ht_new # => "{"test": "abc", "testing": "fun"}"
Additionally, how can we return values from:
arr = ["abc", "123"]
ht = [{"key": "abc", "value": "test"}, {"key": "123", "value": "money"}, {"key": "doremi", "value": "rain"}}]
output # => [{"key": "abc", "value": "test"}, {"key": "123", "value": "money"}]
ht_new = ht.select {|hashes| arr.include? hashes}intended to stand for? Is it your failed attempt? Or are you claiming that it returns{"test": "abc", "testing": "fun"}, which is a lie, since a key-value pair is compared witharr, and furthermore, no key inhtmatchesarrunless you convert from string to symbol?htis not valid Ruby expression. Your second question is also not clear.