< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #12125 has been updated by Jrg W Mittag.
A proposal that has existed for years, if not decades, is to deprecate usage of the `::` double colon binary infix namespace operator for message sends, and instead re-use it for method references:
~~~ruby
Dir["*/*.c"].map(&File::basename)
~~~
This is also the syntax chosen by Java for method references.
There is one big problem, though: ambiguity with constant references for methods which start with an uppercase letter. Maybe, it would be possible to require parentheses in that case?
~~~ruby
%w[1 2 3].map(&::Integer())
~~~
----------------------------------------
Feature #12125: Proposal: Shorthand operator for Object#method
https://bugs.ruby-lang.org/issues/12125#change-57415
* Author: Stefan Merettig
* Status: Open
* Priority: Normal
* Assignee:
----------------------------------------
Hello,
The `&` operator lets one pass a `#call`-able object as block.
Really useful feature, but at the moment, if you want to pass a `Method` this way the syntax is not really concise:
```ruby
Dir["*/*.c"].map(&File.method(:basename))
```
More often than not, at least I end up writing this instead `.map{|a| File.basename a}` which isn't that great either.
Thus, I want to propose adding a short-hand operator to the ruby language, which simply calls `#method` on an `Object`.
It could look like this: `an_object->the_method` which is 100% equivalent to doing `an_object.method(:the_method)`
I'm reusing the `->` operator which is already used for the stabby lambda. But I think it makes sense: You have an object,
and from that object you point at a method to get it as `Method`.
With this, the example from above becomes: `Dir["*/*.c"].map(&File->basename)`
I attached a proof of concept patch. When you apply this to trunk, you can try the example above yourself.
Do note however that this PoC also breaks stabby lambda for the moment. I'll work on fixing that the following
days.
Thank you for reading,
Stefan.
---Files--------------------------------
method_shorthand.diff (740 Bytes)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>