Feature #10318
open[PATCH 0/n] Let underscore be positionally matched arg to omit binding obvious variable.
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
Updated by gogotanaka (Kazuki Tanaka) almost 10 years ago
Updated by sawa (Tsuyoshi Sawada) almost 10 years ago
When there is more than one parameter passed to a block, your proposal will create a problem.
When the number of parameters passed to a block is more than the number of block variables in ||
, then destructive assignment should apply, but your proposal will make this not happen. It will be incompatible with many existing code.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
Why expanding tabs?
Updated by gogotanaka (Kazuki Tanaka) almost 10 years ago
@Tsuyoshi Sawada san
Thank you for your comment. I got your point.
As you said (and I mentioned also) it has much pain, so I can't implement right now.
How do you think about the case giving a argument?
I mean like that.
['foo', 'bar', 'foobar'].select { _.include?('foo') }
['foo', 'bar', 'foobar'].each { eval(_) }
Updated by gogotanaka (Kazuki Tanaka) almost 10 years ago
@Nobuyoshi Nakada san
Thank you for your comment.
Starting to implement this issue, I find spaces and tabs being mixed.
And I suppose this might make us confusion and there are no reason spaces and tabs be mixed, but I am afraid a conflict.
This is why I upload this patch at first.
Updated by nobu (Nobuyoshi Nakada) almost 10 years ago
Welcome to the underground holy war. ;)
You may know that ruby-style.el has (indent-tabs-mode . t)
.
Updated by gogotanaka (Kazuki Tanaka) almost 10 years ago
@Nobuyoshi Nakada san
It was an honor to encounter such a underground holy war.
Sure. I'll follow what you said.
Thank you.
Updated by gogotanaka (Kazuki Tanaka) almost 10 years ago
oops... I found totally incompatible code in Rails project.
I gave up this approach. Nonetheless, I still wanna introduce concept omitting obvious variable. (Like Scala's lambda calculus)
#10394 does make sense so far?