Actions
Feature #20657
closedAllow Enumerable#map(&:method) and #each accept additional parameters for method
Status:
Feedback
Assignee:
-
Target version:
-
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
Like0
Like0Like0Like0Like0