Modernize Ruby idioms in Configuration and tsearch#572
Merged
Conversation
The pattern reduce({}) { |hash, k| hash.tap { hash[k] = v } } is an
anti-idiom: when the accumulator is the same hash being yielded each
iteration, each_with_object expresses intent more directly, and to_h
with a block does so even better when there are no conditionals.
The previous form used {}.tap with features.map and assigned into the
captured hash, which is the long way to write to_h. As a bonus, this
also removes the latent oddity that map was used purely for its side
effect.
Single-expression accessors in Configuration read better as endless methods. Multi-line bodies, methods with guards (regular_columns, associations), and the now-multi-line feature_options are left alone.
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
reduce({})+hash.taphash builders in tsearch'sheadline_optionsanddeprecated_headline_optionswithto_handeach_with_object— the previous form yielded the accumulator and assigned into it, which is whatto_h/each_with_objectexpress directly.Configuration#feature_optionswithfeatures.to_h { ... }instead of{}.tap { features.map { ... } }. As a bonus this also removes the latent oddity thatmapwas used purely for its side effect.Configuration(columns,query,ignore,ranking_sql,features,associated_columns,order_within_rank) to endless method syntax now that Ruby 3.3 is the floor.Test plan
bin/rspecpasses (254 examples, 0 failures locally)bin/standardrbis clean🤖 Generated with Claude Code