File: keep_if.rb

package info (click to toggle)
ruby-backports 3.25.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,759; makefile: 6
file content (8 lines) | stat: -rw-r--r-- 173 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
unless Array.method_defined? :keep_if
  class Array
    def keep_if
      return to_enum(:keep_if) unless block_given?
      delete_if{|elem| !yield elem}
    end
  end
end