LoginSignup
7
1

More than 5 years have passed since last update.

1,2月で気になった Ruby のパッチ、提案

Last updated at Posted at 2018-03-05

ブログ記事からの転載です。

去年、Ruby のパッチを書き始めた頃から開発者向けの ML に参加しているんですが、その中で面白そうなパッチや提案が結構目に付くので定期的にまとめてみようかと。

Feature #13784: Add Enumerable#filter as an alias of Enumerable#select - Ruby trunk - Ruby Issue Tracking System

Enumerable#filterEnumerable#select の alias にする提案。
提案自体は去年されていたんですが、最近取り込まれました。
先日リリースされた Ruby 2.6 preview 版にもすでに実装されています。
確かに名前は filter の方が直感的だと思うんですが、これにより find_allselectfilter と同等のメソッドが3つ存在することに…。

Feature #14371: New option "recursive: true"; for Hash#transform_keys! - Ruby trunk - Ruby Issue Tracking System

Ruby 2.5 で追加された Hash#transform_keys! を再帰的に適用させたい、みたいな提案だったんですが、残念ながら reject されました。
これに関しては matz がコメントしているのでそっちを参照してください。

Feature #14390: UnboundMethod#to_proc - Ruby trunk - Ruby Issue Tracking System

UnboundMethod#to_proc を追加して、第一引数をレシーバとして扱うような提案…かな?
多分以下のような挙動を想定。

to_s = Integer.instance_method(:to_s)

# 従来の使い方
p to_s.bind(42).call 2
# => "101010"

# 提案された使い方
# 第一引数を bind する
p to_s.to_proc.call 42, 2
# => "101010"

確かにこれがあるといろいろとできそうな気がする。

Feature #13581: Syntax sugar for method reference - CommonRuby - Ruby Issue Tracking System

これ、スレッド内でかなり議論されているんですが、やりたいことは単純で X.method(:hoge) のシンタックスシュガーがほしいという要求です。
わたしもこれがめちゃくちゃ欲しいんですが、どういうシンタックスシュガーがいいのか…。
あと instance_method のシンタックスシュガーがほしい〜〜〜〜〜〜。

Feature #5120: String#split needs to be logical - Ruby trunk - Ruby Issue Tracking System

これもかなり昔から提案されていたみたいなんですが、最近ちょっと話題になって正式に reject されました。
確かに "".split('') # => [''] になったほうが自然な気がしますが、まあいまから仕様を変えるのも大変そう。

Feature #14498: Class#to_proc - Ruby trunk - Ruby Issue Tracking System

Class#to_procClass#new を呼び出す提案。
ぱっとみ便利そうなんですが、to_proc を潰すのはもったいないので、これぐらいなら Dog.method(:new) 使えばいいかなーという感じ。
可読性の観点からもよくないということで reject されています。

7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1