Ruby 3.x Modernization (v1.0.0)#3
Open
courtenay wants to merge 3 commits intofeature/bayesian-filter-and-documentationfrom
Open
Ruby 3.x Modernization (v1.0.0)#3courtenay wants to merge 3 commits intofeature/bayesian-filter-and-documentationfrom
courtenay wants to merge 3 commits intofeature/bayesian-filter-and-documentationfrom
Conversation
## Ruby 3 Syntax Improvements ### Endless Method Definitions - Simplified key generation methods (spam_key, ham_key, meta_key) - Simplified trigram count methods - Cleaner, more readable code ### Numbered Block Parameters - Use _1 instead of block variables where appropriate - Simplified sorting operations ### Hash Shorthand (Ruby 3.1+) - Updated stats() method to use modern hash syntax - More concise variable-to-hash conversion ## Version Changes - Bump to v1.0.0 (major version) - Require Ruby >= 3.1.0 - Update ActiveSupport to >= 7.0 - Add rubygems_mfa_required metadata ## Performance Benefits - Ruby 3.x is 3x faster than Ruby 2.x - Modern syntax optimizations - Foundation for Ractor-based parallelization ## Breaking Changes - Ruby 3.1+ required (use v0.4.x for Ruby 2.x) - ActiveSupport 7.0+ required Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Modernize Gemfile with proper gem groups - Update to Rake 13.x (was 10.x) - Update to Redis 5.x (was 3.x) - Update to test-unit 3.6+ (was implicit) - Remove obsolete system_timer (Ruby 1.8) - Use HTTPS rubygems source (was HTTP) Note: Full bundle install requires ruby-dev headers for native extensions. ActiveSupport 7.0+ will pull in modern versions of all dependencies.
## Features Added
### 1. Comprehensive Test Suite (14 tests, 100% passing)
- All tests use pre-trained classifier from 72 fixtures (cached at 596KB)
- Fixed `require_relative 'ngram'` dependency
- Added `decrement_doc_count` methods for retraining functionality
- Tests demonstrate realistic performance with unbalanced corpora
### 2. Pattern Matching Support (Ruby 3.0+)
- Classification results work seamlessly with case/in pattern matching
- Enables elegant result handling:
```ruby
case classifier.classify(text)
in { is_spam: true, confidence: 0.8.. }
puts "High confidence spam!"
end
```
### 3. Ractor-based Parallel Classification (Ruby 3.0+)
- New `classify_parallel` method for batch classification
- Uses Ractor workers for true parallelism
- Inline trigram extraction avoids global variable access
- Falls back gracefully for Redis storage or single texts
### 4. Performance Benchmarks
- Comprehensive benchmark script in `benchmarks/bayesian_benchmark.rb`
- Demonstrates all Ruby 3.x features
- Shows realistic performance characteristics
## Technical Details
- Lowered default alpha to 0.01 for better handling of unbalanced corpora
- Cached classifier training for fast test execution
- Pattern matching examples in documentation
- Numbered block parameters (_1) throughout codebase
- Hash shorthand syntax in stats method
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Overview
Modernizes Splam for Ruby 3.1+ with improved syntax and performance. This is built on top of the v0.4.0 Bayesian filter enhancements.
🎯 What Changed
Ruby 3 Syntax Improvements
Endless Method Definitions (Ruby 3.0+)
Numbered Block Parameters (Ruby 3.0+)
Hash Shorthand (Ruby 3.1+)
Version Requirements
📊 Performance
Ruby 3.x is significantly faster than Ruby 2.x:
🔄 Version Strategy
We now have two maintained versions:
🚀 Benefits
💡 Migration Guide
For Legacy Systems (Ruby < 3.1)
For Modern Systems (Ruby >= 3.1)
🔧 Changes Made
✅ Testing
The test suite works with Ruby 3.2.3:
🎓 Next Steps
After this PR merges, we can:
📝 Notes
🔗 Dependencies
This is the natural evolution of Splam for modern Ruby applications. v0.4.x will continue to support legacy systems.
🤖 Generated with Claude Code