From 9422fdbc87cc5310d7f0d5b1b9039fae1b6aa425 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 14 May 2021 10:39:41 +0900 Subject: mruby-array-ext/array.c: implement `Array#compact` in C. --- mrbgems/mruby-array-ext/mrblib/array.rb | 35 --------------------------------- 1 file changed, 35 deletions(-) (limited to 'mrbgems/mruby-array-ext/mrblib/array.rb') diff --git a/mrbgems/mruby-array-ext/mrblib/array.rb b/mrbgems/mruby-array-ext/mrblib/array.rb index 47446181e..79fcca34e 100644 --- a/mrbgems/mruby-array-ext/mrblib/array.rb +++ b/mrbgems/mruby-array-ext/mrblib/array.rb @@ -294,41 +294,6 @@ class Array end end - ## - # call-seq: - # ary.compact -> new_ary - # - # Returns a copy of +self+ with all +nil+ elements removed. - # - # [ "a", nil, "b", nil, "c", nil ].compact - # #=> [ "a", "b", "c" ] - # - def compact - result = self.dup - result.compact! - result - end - - ## - # call-seq: - # ary.compact! -> ary or nil - # - # Removes +nil+ elements from the array. - # Returns +nil+ if no changes were made, otherwise returns - # ary. - # - # [ "a", nil, "b", nil, "c" ].compact! #=> [ "a", "b", "c" ] - # [ "a", "b", "c" ].compact! #=> nil - # - def compact! - result = self.select { |e| !e.nil? } - if result.size == self.size - nil - else - self.replace(result) - end - end - # for efficiency def reverse_each(&block) return to_enum :reverse_each unless block -- cgit v1.2.3