Project

General

Profile

Actions

Feature #10318

open

[PATCH 0/n] Let underscore be positionally matched arg to omit binding obvious variable.

Added by gogotanaka (Kazuki Tanaka) about 10 years ago. Updated almost 4 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:65373]

Description

I’m so sorry for just proposing this future without PATCH right now ...

(I suppose it contains too much issues.)

After some discussions, let me implement this future.

Of course I need to obtain your consent.

Anyway, I want to let underscore be positionally matched arg and omit to binding obvious variable when it comes to proc, lambda and block .

# let items be a Array of String. (e.g. items = ['foo', 'bar', 'foobar']

# Before
items.select { |item| item.include?('foo') }

# After
items.select { _.include?('foo') }

Even if block has more than 2 args, I want to omit one of them.

(I know it has much pain ... just idea)

# let nums be a Array of Integer. (e.g. nums = [1, 2, 3, 4]

# Before
nums.inject { |sum, num| sum + num }

# After
nums.inject { |sum| sum + _ }
#↑ It seems to difficult to hundle .. but looks aesthetic or understandable.

Let me know how do you think about it or what problem is.

thank you. gogo.


Files

convert_tabs_to_spaces.patch (29.3 KB) convert_tabs_to_spaces.patch gogotanaka (Kazuki Tanaka), 10/05/2014 10:46 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0