Could be done with facets library (a missing features from standard library), like that:
require 'hash/compact'
require 'enumerable/recursively'
hash.recursively { |v| v.compact! }
Works with any Enumerable (including Array, Hash).
Look how recursively method is implemented.