Mega Code Archive

 
Categories / Ruby / Hash
 

Searching a Hash with Regular Expressions

h = { "apple tree" => "plant", "ficus" => "plant",       "shrew" => "animal", "plesiosaur" => "animal" } h.keys.grep /p/ # => ["apple tree", "plesiosaur"]