Mega Code Archive

 
Categories / Ruby / Hash
 

Delete_if uses a block

# It removes the key-values from the hash for which the block evaluates to true. myHash = { 1 => "One", 2 => "Two", 3 => "Three", 4 => "Four", 5 => "Five" } # With delete_if, I'll remove all pairs whose key values are less than 3: myHash.delete_if { |key, value| key < 3 }