Skip to content
This repository
Browse code

add Array #compact #compact!.

  • Loading branch information...
commit ab3a3b30bdfe9bddc3d2d0271484719bcaacd434 1 parent 4504c99
Kouki Ooyatsu kouki-o-iij authored

Showing 1 changed file with 11 additions and 0 deletions. Show diff stats Hide diff stats

  1. +11 0 mrblib/array.rb
11 mrblib/array.rb
@@ -136,6 +136,17 @@ def flatten(depth=nil)
136 136 def flatten!
137 137 self.replace(self.flatten)
138 138 end
  139 +
  140 + def compact
  141 + result = self.dup
  142 + result.compact!
  143 + result
  144 + end
  145 +
  146 + def compact!
  147 + result = self.select { |e| e != nil }
  148 + self.replace(result)
  149 + end
139 150 end
140 151
141 152 ##

0 comments on commit ab3a3b3

Please sign in to comment.
Something went wrong with that request. Please try again.