Actions
Feature #15922
openEnumerable#partition(pattern)
Status:
Open
Assignee:
-
Target version:
-
Description
-
any?
all?
one?
none?
already can take pattern argument. ref: https://bugs.ruby-lang.org/issues/11286 -
select
reject
is proposed to take pattern argument. ref: https://bugs.ruby-lang.org/issues/14197
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
Like0