I have an usecase where i wanted to fetch the keys from hash. I wanted to return the all keys which are present in the array.
Example:
h = {"video"=>"MP4","audio"=>"MP3", "sharing"=>"NONE", "mix"=>"NONE"}
a = ["video", "audio", "txt"]
Expected result:
h.slice(a)
["video","audio"]
I am trying to use slice method on hash but it is not working for me.
Any help would be appreciated.
a = ["video", "audio", "txt"]({"video", "audio", "txt"}is an invalid expression). If you want all keys ofhthat are ina,h.keys & a #=> ["video", "audio"]. If you want all key-value pairs inhfor which the key is ina,h.slice(*a) #=> {"video"=>"MP4", "audio"=>"MP3"}. - Cary Swoveland