Find key that contains certain characters in a hashtable with Ruby -
i have hash that's this:
hash = { "key1-one" => 3, "key1-two" => 6, "key2-one" => 5, "key2-two" => 9 } now want find values keys starting key1, regardless of follows. i've tried has_key? doesn't seem work. know can use regex there built-in method ruby?
hash.select{ |key, _| key.start_with?("key1") }.values
Comments
Post a Comment