Actions
Feature #17663
openEnumerator#with, an alternative to Enumerator#with_object
Feature #17663:
Enumerator#with, an alternative to Enumerator#with_object
Status:
Open
Assignee:
-
Target version:
-
Description
Enumerator#with yields each element along with the arguments
class Enumerator
def with(*options)
return to_enum(:with, *options) unless defined? yield
each do |entry|
yield entry, *options
end
end
end
Suppose we have a proc that accepts more than 1 argument.
Normally to apply the argument we enclosed it in a block, like so:
I found Enumerator#with_object method awkward to use.
Tried simplifying this code further, but Enumerator#with_object ignores the given block and just returns the argument.
Compare to how concise this line using Enumerator#with
Actions