diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-09 21:21:31 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-08-09 21:21:31 +0900 |
| commit | 24c345fe5c68a3f0cd4d16e84c8bf6ed93cedce8 (patch) | |
| tree | 4ca852347e8c94c8ab6114a0ff98657f9450e0f4 /mrbgems/mruby-hash-ext/mrblib/hash.rb | |
| parent | f9c3ebd29d7410be209b3f22b9923f0f81f0141d (diff) | |
| parent | 6c61a60609e973f3dec00e86ca6f1519ae83e1e3 (diff) | |
| download | mruby-24c345fe5c68a3f0cd4d16e84c8bf6ed93cedce8.tar.gz mruby-24c345fe5c68a3f0cd4d16e84c8bf6ed93cedce8.zip | |
Merge branch 'vvakame-add-hash-compact'
Diffstat (limited to 'mrbgems/mruby-hash-ext/mrblib/hash.rb')
| -rw-r--r-- | mrbgems/mruby-hash-ext/mrblib/hash.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/mrbgems/mruby-hash-ext/mrblib/hash.rb b/mrbgems/mruby-hash-ext/mrblib/hash.rb index 846cba9ff..73d1fbe6d 100644 --- a/mrbgems/mruby-hash-ext/mrblib/hash.rb +++ b/mrbgems/mruby-hash-ext/mrblib/hash.rb @@ -115,6 +115,22 @@ class Hash alias update merge! ## + # call-seq: + # hsh.compact -> new_hsh + # + # Returns a new hash with the nil values/key pairs removed + # + # h = { a: 1, b: false, c: nil } + # h.compact #=> { a: 1, b: false } + # h #=> { a: 1, b: false, c: nil } + # + def compact + result = self.dup + result.compact! + result + end + + ## # call-seq: # hsh.fetch(key [, default] ) -> obj # hsh.fetch(key) {| key | block } -> obj |
