Ruby - Hash Element Deleting Conditionally

Introduction

To delete any hash elements whose value is below a certain figure. Here's an example of how to do this:

Demo

x = { "a" => 100, "b" => 20 } 
p x # from ww  w  .  j a  va2s  .c o  m

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

Result

Related Topic