From: s@... Date: 2015-12-15T13:57:05+00:00 Subject: [ruby-core:72147] [Ruby trunk - Feature #11818] `Hash#compact` Issue #11818 has been updated by Prem Sichanugrist. Active Support has this: http://api.rubyonrails.org/classes/Hash.html#method-i-compact I'm +1 on porting this method. While I think it's possible using a block form and `delete_if`, this method has a good name and intention that could live by its own. ---------------------------------------- Feature #11818: `Hash#compact` https://bugs.ruby-lang.org/issues/11818#change-55557 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: ---------------------------------------- I request `Hash#compact` and `Hash#compact!` that remove the key-value pairs whose value is `nil`, as follows: h1 = {a:, 1, b: nil, c: 2} h1.compact # => {a: 1, c: 2} h1 # => {a: 1, b: nil, c: 2} h2 = {a:, 1, b: nil, c: 2} h2.compact! # => {a: 1, c: 2} h2 # => {a: 1, c: 2} h3 = {a:, 1, c: 2} h3.compact! # => nil h3 # => {a: 1, c: 2} I believe people have frequent need to do this. -- https://bugs.ruby-lang.org/