Remove duplicate definitions causing method-redefined warnings (#1434)#1677
Open
ryoya1122 wants to merge 1 commit into
Open
Remove duplicate definitions causing method-redefined warnings (#1434)#1677ryoya1122 wants to merge 1 commit into
ryoya1122 wants to merge 1 commit into
Conversation
…erecord-hackery#1434) Three methods were defined twice in the same class, causing Ruby to emit 'method redefined; discarding old ...' warnings whenever the gem is required with warnings enabled. The first definition in each pair was dead code: it was shadowed by a later, real implementation. * `Ransack::Nodes::Condition#arel_predicate` was defined as a stub raising "not implemented" and re-defined further down with the actual implementation. * `Ransack::Nodes::Grouping#conditions` had an `attr_reader` that was immediately shadowed by an explicit `def` doing lazy init. * `Ransack::Context#arel_visitor` was listed in two consecutive `attr_reader` calls. Dropping the dead definitions removes the warnings without any behavioural change (the live implementations were already the ones in effect).
a8359df to
c732757
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.
Closes #1434.
Problem
Loading the gem with warnings enabled (e.g.
ruby -Wor RSpec under-w) emits three "method redefined" warnings:The reporter saw the
arel_predicateone in #1434; the same root cause produces two more.Cause
Three methods were defined twice in the same class. In each case the first definition was dead code — it was shadowed by a later real implementation:
lib/ransack/nodes/condition.rbdef arel_predicate; raise "not implemented"; end(was at L220)lib/ransack/nodes/grouping.rbattr_reader :conditions(was at L4)def conditions; @conditions ||= []; endat L29 (lazy-inits the array)lib/ransack/context.rbattr_reader :arel_visitor(was at L7)attr_readerone line earlierFix
Delete the dead definitions. No behavioural change — the live implementations were already the ones in effect at runtime.
Verification
Before:
After:
(Two unrelated "assigned but unused variable" warnings in
adapters/active_record/context.rbremain — different category, out of scope for #1434.)Compatibility
The three deleted lines were dead code, shadowed by the live definitions next to them. Behaviour is identical before and after; the only difference is the absence of the warnings on load. Diff is
-6 / +0.Full suite:
514 examples, 0 failures, 1 pendingonv5.0.0+ this branch (SQLite, ActiveRecord 7.2.3.1, Ruby 3.4.9).Targets
v5.0.0per #1640.