Home > Net >  Ruby on Rails: Return values not blank/empty/false/nil
Ruby on Rails: Return values not blank/empty/false/nil

Time:10-29

I have this

 hash = {"foo"=>nil,"bar"=>false,"zoo"=>"monkey","loo"=>"","hoo"=>"   "}

I want to reject foo, loo, and hoo

what is the appropriate method to do that?

CodePudding user response:

code

 p hash.delete_if{|_,v| v.to_s.strip.empty? }
  • Related