I have a hash h1, and key k1. I need to return complete key value pair for the given key in the hash.
Like for key ‘fish’
i need to print ‘fish’ => ‘aquatic animal’
@h1, prints all the key value pairs.I need the way to print the key value pair for thr given key
I am quite new to ruby, so sorry for the noobish question.
There is a method, Hash#assoc can do similar things. But it returns the key and value in an array, which you can easily change it into a hash.
And an alternative is use Hash#select, which does return a hash according to the block given.