-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Simplify parameter matcher for hashes #739
Open
nitishr
wants to merge
24
commits into
freerange:main
Choose a base branch
from
nitishr:simplify-parameter-matcher-for-hashes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Simplify parameter matcher for hashes #739
nitishr
wants to merge
24
commits into
freerange:main
from
nitishr:simplify-parameter-matcher-for-hashes
Conversation
This file contains 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
the previous test asserted _should_match_ and the test deleted here asserted _should_not_match_. The reason it did not match is because the entry did not match (due to an extra k3: 'v3'). It had nothing to do with keyword argument matching.
Expected keyword args will always be the last args anyway. So, if a positional hash matches keyword args but isn't the last one, the expectation will fail regardless as the remaining args won't have any matcher to match with.
The subclasses didn't seem to be pulling their weight anymore. A hook method where only one of the subclasses wants to customize the hook/do additional checks seems like a force-fitted design choice.
3d7a06c
to
6ddc23b
Compare
@floehopper I started some comprehension refactoring in order to investigating #594 and #734. In the process, I noticed a number of opportunities for simplification, and the PR is the result. |
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.
Improves the handling of keyword and positional hash argument matching. Simplifies the logic around matching keyword and positional hashes, removes redundant code, and ensures that the behavior aligns with Ruby's keyword argument handling.
Key Changes:
Simplified
to_matcher
Method:last
parameter from theto_matcher
method ininstance_methods.rb
. This simplifies the logic and removes unnecessary complexity in determining whether a matcher is the last in a sequence.Refactored
PositionalOrKeywordHash
Class:last_expected_value
parameter and related logic from thePositionalOrKeywordHash
class. The class now focuses on matching hash entries exactly and handling keyword arguments more straightforwardly.matches?
method to handle both positional and keyword hashes without needing to check if the matcher is the last one.matches_last_actual_value?
andlast_expected_value_is_positional_hash?
.Updated Tests:
last
parameter, as it is no longer relevant.strict_keyword_argument_matching_test.rb
to reflect the new behavior, ensuring that positional and keyword arguments are matched correctly.