< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #12495 has been updated by Eregon (Benoit Daloze).
:+1:
Note there is some inconsistency with e.g. `attr_reader` always returning an array (#6470):
```ruby
class F
attr_reader :a # => [:a]
end
```
But I think it does not matter too much.
`private` also accepts a single Array argument since #17314, so such decorators should probably always accept either an Array or a Symbol.
----------------------------------------
Feature #12495: Make "private" return the arguments again, for chaining
https://bugs.ruby-lang.org/issues/12495#change-94379
* Author: herwinw (Herwin Quarantainenet)
* Status: Open
* Priority: Normal
----------------------------------------
Ruby 2.1 introduced the feature to make `def foo` return the symbol, so this could be used by things like `private` (see #3753):
```ruby
private def foo() end
```
You could use the same method to create your own decorators (name borrowed from Python)
```ruby
def cached(name)
# Rewrite method to include a cache
return name
end
private cached def foo() end
```
Currently, this would work but `cached private def foo()` would not. `private` (and all other modifier functions) return the class on which it was called. It would be nice to exterminate those order-dependencies.
The attached patch fixes this. It includes three modes:
No arguments: return `nil`:
```ruby
private
def foo() end
```
One argument: return the symbol. The would be the most common use case for this example.
```ruby
private def foo() end
private :bar
```
Multiple arguments: return an array of the arguments:
```ruby
private :foo, :bar
```
---Files--------------------------------
ruby_return_symbols_in_private.diff (1.19 KB)
--
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>