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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -