Collapse extract_handler type-dispatch into case/when#2698
Open
ericproulx wants to merge 1 commit intomasterfrom
Open
Collapse extract_handler type-dispatch into case/when#2698ericproulx wants to merge 1 commit intomasterfrom
ericproulx wants to merge 1 commit intomasterfrom
Conversation
`DSL::RequestResponse#extract_handler` dispatched on `with`'s type via three `with.instance_of?` predicates, each on its own line. Lift the dispatch into a single `case`/`when` block. Branches stay as plain expressions per the project style; the early returns above the `case` short-circuit when there's no `with` to inspect. Side effect: `case`/`when` uses `===` (i.e. `is_a?`), not `instance_of?`. So a hypothetical `Symbol`/`String`/`Proc` *subclass* now matches where it didn't before — `is_a?` is the more conventional check and handles inheritance correctly. None of the codebase or tests rely on the strict-instance behavior. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1571156 to
fc13b25
Compare
Danger ReportWarnings
MarkdownsHere's an example of a CHANGELOG.md entry: * [#2698](https://github.com/ruby-grape/grape/pull/2698): Collapse extract_handler type-dispatch into case/when - [@ericproulx](https://github.com/ericproulx). |
Danger ReportNo issues found. |
dblock
approved these changes
May 2, 2026
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
DSL::RequestResponse#extract_handlerdispatched onwith's type via threewith.instance_of?predicates on consecutive lines. Lift the dispatch into a singlecase/whenblock. Branches stay as plain expressions (no return insidewhen), with early returns above thecaseto short-circuit the no-withpaths.Behavior note
case/whenuses===(i.e.is_a?), notinstance_of?. So a hypotheticalSymbol/String/Procsubclass now matches where it didn't before.is_a?is the more conventional check and handles inheritance correctly; nothing in the codebase or tests relies on the strict-instance behavior.Test plan
bundle exec rspec— green (2236 examples).bundle exec rubocopon touched file — clean.🤖 Generated with Claude Code