Deleting Hash Elements Conditionally : delete_if « Hash « Ruby






Deleting Hash Elements Conditionally



x = { "a" => 100, "b" => 20 }

x.delete_if { |key, value| value < 25 }

puts x.inspect

 








Related examples in the same category

1.Delete if with block logics
2.Delete if for a certain value
3.delete_if uses a block
4.delete_if passes all pairs into the block, so you can delete based on a key or a value.