Replace .tap usages in lib/ with explicit local variables#2701
Open
ericproulx wants to merge 1 commit intomasterfrom
Open
Replace .tap usages in lib/ with explicit local variables#2701ericproulx wants to merge 1 commit intomasterfrom
ericproulx wants to merge 1 commit intomasterfrom
Conversation
71c9288 to
095458a
Compare
Danger ReportNo issues found. |
`.tap` is idiomatic when you want to perform side effects on a value
and return the value unchanged, but most uses in lib/ were just a
ceremony for "build up a fresh value, then return it" — clearer as
plain locals.
Refactors across 11 files:
- `[].tap { |parts| ... }` → local + explicit return
- `Class.new.tap { |instance| ... }` → local + explicit return
- `Strategies[type].tap { raise unless ... }` → assign-then-raise
- `Rack::Builder.new.tap { ... }` → local + explicit return
- `self.class.new.tap { |s| ... }` → local + explicit return
- `keys.tap { concat + uniq! }` → `(a + b).uniq` with guard clause
- `{}.tap { |details| ... }` → local + explicit return
- `Array.wrap(x).tap { ... }.join(...)` → local, then join
- `Module.new.tap { |mod| ... }` → local + explicit return
- `||= …new.tap { … }` memoization → early-return memoization
Drive-by: replace `handler.instance_of?(Symbol)` with
`handler.is_a?(Symbol)` in `Middleware::Error#run_rescue_handler`
for consistency with the rest of the file (Symbol can't be
subclassed, so the two are behaviorally equivalent here).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
095458a to
c210eea
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`.tap` is idiomatic when you want to perform side effects on a value and return the receiver unchanged, but most uses in `lib/` were a ceremony for "build a fresh value, mutate it a bit, return it" — clearer as plain locals. Refactor across 11 files:
Drive-by: `handler.instance_of?(Symbol)` → `handler.is_a?(Symbol)` in `Middleware::Error#run_rescue_handler` for consistency with the rest of the file. Symbol can't be subclassed in MRI, so the two are behaviorally equivalent here.
Test plan
🤖 Generated with Claude Code