A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/rubocop/rubocop/issues/14416 below:

Ambiguous/Unwarranted suggestion on map(block).to_h(block) · Issue #14416 · rubocop/rubocop · GitHub

Seems like an obvious issue that has been considered during implementation of this cop, but couldn't find any duplicates searching for "map to_h", so reporting just in case.

Steps to reproduce the problem
[1, 2, 3].map { it * 10 }.to_h do
  [it, it * 100]
end.then { pp it }
Actual behavior

Says Style/MapToHash: Pass a block to to_h instead of calling map.to_h.

Replacing map with to_h will obviously break the code, as to_h belongs to its following block

The message could implicitly hint at merging the code like so, but this requires some lenience on the reader's part.

[1, 2, 3].to_h do
  it *= 10
  [it, it * 100]
end.then { pp it }
Expected behavior

A) Whitelist it (preferably)
B) Suggest something like "merge the blocks", but original code might be perfectly acceptable for clarity (so rather not)

RuboCop version
ruby   : 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [arm64-darwin24]
rubocop: git 2025-08-04 12:08:56 eb470cef9
System : macOS 15.5 (24F74)
Model  : MacBookAir10,1

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4