Project

General

Profile

Actions

Feature #11446

open

Possible work around for the requirement to supplying arguments like this: .map(&:method, <arguments>)

Added by jikkujose (Jikku Jose) over 9 years ago. Updated 9 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

Any chance this work around can be considered to be part of the language. Seems to be a pretty neat.

NB: Matz seems to be interested in having this added: Check his tweet.

Updated by artemb (Artem Borodkin) 9 months ago

Are there any proposal issues regarding the addition of argument and block support for the .each(&:method, args) do; end syntax?

It seems quite feasible to support it natively.

module Enumerable
  def each_call(method, *args,  &) = each { _1.send method, *args, & }
  def map_call!(method, *args,  &) = map! { _1.send method, *args, & }
  # ...
end

# [1,2].map! &:+, 1
[1,2].map_call! :+, 1

# [].each &:instance_eval do
%w[1 2].each_call :instance_eval do
  @v = 1
end
Actions

Also available in: Atom PDF

Like1
Like0