Permalink
Browse files

add Array #compact #compact!.

  • Loading branch information...
1 parent 4504c99 commit ab3a3b30bdfe9bddc3d2d0271484719bcaacd434 Kouki Ooyatsu committed Oct 11, 2012
Showing with 11 additions and 0 deletions.
  1. +11 −0 mrblib/array.rb
View
@@ -136,6 +136,17 @@ def flatten(depth=nil)
def flatten!
self.replace(self.flatten)
end
+
+ def compact
+ result = self.dup
+ result.compact!
+ result
+ end
+
+ def compact!
+ result = self.select { |e| e != nil }
+ self.replace(result)
+ end
end
##

0 comments on commit ab3a3b3

Please sign in to comment.