Skip to content

Conversation

@Maumagnaguagno
Copy link
Contributor

Enumerable#filter_map is available since Ruby 2.7.


assert_match(/irbtest-.*\.rb:2:in (`|'Object#)foo': error \(RuntimeError\)/, output)
frame_traces = output.split("\n").select { |line| line.strip.match?(/from /) }.map(&:strip)
frame_traces = output.split("\n").filter_map { |line| line.strip if line.strip.match?(/from /) }
Copy link
Member

@tompng tompng May 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other part of this pull request looks good.
This part, I'm not sure if this change is obviously better than before.

How about changing it to .map(&:strip).grep(/from /) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is much better!

@Maumagnaguagno Maumagnaguagno changed the title Prefer filter_map instead of map+compact and select+map Prefer filter_map and map+grep instead of map+compact and select+map May 6, 2025
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@tompng tompng merged commit 3265f09 into ruby:master May 6, 2025
33 checks passed
@Maumagnaguagno Maumagnaguagno deleted the filter_map branch May 6, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants