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

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

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -