Project

General

Profile

Actions

Feature #20657

closed

Allow Enumerable#map(&:method) and #each accept additional parameters for method

Added by ukolovda (Dmitry Ukolov) 4 months ago. Updated 4 months ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:118737]

Description

I can use #map (or #each) with short method name, for example:

a = ["a1", "b1", "c1"]

b = a.map(&:length)
# or
a.each(&:some_method)

But with additional arguments I must use yield:

c = a.map { |item| item.ljust(10) }
# or
a.each { |item| item.some_method(arg1, arg2) }

Direct sending allow make the code more simple:

c = a.map(&:ljust, 10) # Now give syntax error, unexpected ',', expecting ')'
# or
a.each(&:some_method, arg1, arg2) # Now give syntax error, unexpected ',', expecting ')'
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0