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

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -