Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash のインスタンスに対する map { |k, v| [k, v.foo] }.to_h を transform_values にする Cop #33

Closed
sinsoku opened this issue Dec 9, 2017 · 1 comment

Comments

@sinsoku
Copy link
Collaborator

sinsoku commented Dec 9, 2017

h = { a: 1, b: 2 }
h.map { |k, v| [k, v.to_s] }.to_h

上記のコードは transform_values で置き換えることができます。

h = { a: 1, b: 2 }
h.transform_values(&:to_s)

注意する点

map は Enumerable のメソッド

map メソッドでブロック引数が2つあれば、おそらく Hash のインスタンスだとは思うけど、
確定できないので false positive が発生しそうです。

使える環境

古い Ruby/Rails では使用できないメソッドなので、 Cop を作るときに注意が必要そう。

@koic
Copy link
Member

koic commented Sep 30, 2020

rubocop/rubocop#7663 で実現されているためクローズします。

@koic koic closed this as completed Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants