Project

General

Profile

Actions

Feature #15922

open

Enumerable#partition(pattern)

Added by kachick (Kenichi Kamiya) over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:93128]

Description

I would like to use partition with pattern argument for consistency.

module Enumerable
  alias_method :original_partition, :partition

  def partition(*args, &block)
    case args.size
    when 1
      pattern = args.first
      original_partition do |element|
        pattern === element
      end
    when 0
      original_partition(&block)
    else
      raise ArgumentError
    end
  end
end

[1, 2, 3.3, 4, 5.5].partition(Integer)
#=> => [[1, 2, 4], [3.3, 5.5]]

No data to display

Actions

Also available in: Atom PDF

Like0