strain.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
class Array
  def keep
    return enum_for(:keep) { size } unless block_given?

    result = []
    each { |x| result << x if yield(x) }
    result
  end

  def discard
    keep { |x| !yield(x) }
  end
end

@remcopeereboom and @alialliallie think this looks great

Comments

Improvements thanks to @alialliallie and @remcopeereboom !

helenst commented 26 April 2016 at 17:34 UTC

You're not logged in right now. Please login via GitHub to comment