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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -