compact()
public
Returns a new hash with the nil values/key pairs removed
h = { a: 1, b: false, c: nil }
h.compact
h
Show source
static VALUE
rb_hash_compact(VALUE hash)
{
VALUE result = rb_hash_new();
if (!RHASH_EMPTY_P(hash)) {
rb_hash_foreach(hash, set_if_not_nil, result);
}
return result;
}