< :前の番号
^ :番号順リスト
> :次の番号
P :前の記事(スレッド移動)
N :次の記事(スレッド移動)
|<:前のスレッド
>|:次のスレッド
^ :返事先
_:自分への返事
>:同じ返事先を持つ記事(前)
<:同じ返事先を持つ記事(後)
---:分割してスレッド表示、再表示
| :分割して(縦)スレッド表示、再表示
~ :スレッドのフレーム消去
.:インデックス
..:インデックスのインデックス
Issue #13563 has been updated by babanba-n (matzbara masanao).
Sorry,I'm so embarrassed.
https://github.com/baban/ruby/commit/b3b7f5f701e9bfbbc946d27d3397adc1c99125f6
----------------------------------------
Feature #13563: Implement Hash#choice method.
https://bugs.ruby-lang.org/issues/13563#change-65349
* Author: babanba-n (matzbara masanao)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Hi,
I propose Hash#choice method.
It pick up key and value pairs in Hash like a below code.
~~~
{ :a => 1, 2 => "2", "c" => true }.choice(:a, 2) # => { :a => 1, 2 => "2" }
{ :a => 1, 2 => "2", "c" => true }.choice("c", 10000) # => { "c" => true, 10000 => nil }
~~~
This method is useful when Hash have many keys, but programer need few key's.
For instance, it pick up personal data in ActiveRecord model's data, and migrate to new device.
~~~
feature_phone_user = User.find(params[:src_user_id])
profile = feature_phone_user.attributes.choice(*%i[nickname email sex birthday prefecture])
smart_phone_user = User.new
smart_phone_user.attributes = profile
~~~
In other case, it pick up latest log from http request parameter.
~~~
condition = params.to_h.choice("user_id", "service_id")
latest_payment_log = PaymentLog.find_by(condition).last
~~~
If this method exist, I guess that many cases change to comfortable just a little.
Please consider about it.
And I write it.
https://github.com/baban/ruby/commit/4014ebe2ae261881669bef8369eb08aaecef2034
--
https://bugs.ruby-lang.org/