Skip to content

Commit 9ee47a1

Browse files
dominion525crmne
andauthored
Fix method redefined warning for log_regexp_timeout= (Ruby 4.0+) (#721)
## What this does On Ruby 4.0+, `require "ruby_llm"` emits: warning: method redefined; discarding old log_regexp_timeout= The `option` class method generates a setter via `attr_accessor`, which is then overridden by the custom `log_regexp_timeout=` setter. This adds `remove_method` before the redefinition to suppress the warning. A regression spec is included. ## Type of change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation - [ ] Performance improvement ## Scope check - [x] I read the [Contributing Guide](https://github.com/crmne/ruby_llm/blob/main/CONTRIBUTING.md) - [x] This aligns with RubyLLM's focus on **LLM communication** - [x] This isn't application-specific logic that belongs in user code - [x] This benefits most users, not just my specific use case ## Quality check - [x] I ran `overcommit --install` and all hooks pass - [x] I tested my changes thoroughly - [x] All tests pass: `bundle exec rspec` - [ ] I updated documentation if needed - [x] I didn't modify auto-generated files manually (`models.json`, `aliases.json`) ## AI-generated code - [x] I used AI tools to help write this code - [x] I have reviewed and understand all generated code (required if above is checked) ## API changes - [x] No API changes Co-authored-by: Carmine Paolino <carmine@paolino.me>
1 parent efbe8fa commit 9ee47a1

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

lib/ruby_llm/configuration.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def instance_variables
8181
super.reject { |ivar| ivar.to_s.match?(/(_id|_key|_secret|_token|_credential_provider)$/) }
8282
end
8383

84+
remove_method :log_regexp_timeout=
8485
def log_regexp_timeout=(value)
8586
if value && !Regexp.respond_to?(:timeout)
8687
RubyLLM.logger.warn("log_regexp_timeout is not supported on Ruby #{RUBY_VERSION}")

spec/ruby_llm/configuration_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@
6464
)
6565
end
6666
end
67+
68+
describe 'method redefinition warnings' do
69+
it 'does not emit method redefined warning for log_regexp_timeout=' do
70+
warnings = `#{RbConfig.ruby} -W -e 'require "ruby_llm"' 2>&1`
71+
expect(warnings).not_to include('method redefined')
72+
end
73+
end
6774
end

0 commit comments

Comments
 (0)