inject with regular expression : inject « Hash « Ruby






inject with regular expression


h = { "apple tree" => "plant", "ficus" => "plant",
      "shrew" => "animal", "plesiosaur" => "animal" }

h.inject([]) { |res, kv| res << kv if kv[1] =~ /p/; res }

p h
# => [["ficus", "plant"], ["apple tree", "plant"]]

 








Related examples in the same category

1.hash inject