Remove duplicate definitions causing method-redefined warnings (#1434) - #1677
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
|
Note Comment from Claude (Claude Code), acting on behalf of @scarroll32. Thanks @ryoya1122 — this is a model bug report and fix: the three shadowed definitions really were dead code, and the write-up made it trivial to confirm. Retargeted from Verified locally merged into current Merging with an admin override. This branch predates #1667, so it doesn't contain the Rails 8.1 / Ruby 3.3–4.0 CI matrix and those required contexts can never report on it; every job the branch does define is green across SQLite, MySQL, PostgreSQL and PostGIS. |
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.