-
Notifications
You must be signed in to change notification settings - Fork 113
Refactor for improved clarity and update Ruby version #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… separator and format
…nit methods with keyword arguments
… parameter documentation in Configuration and Unit classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors the ruby-units gem to enhance code clarity by adopting modern Ruby 3.2+ features including pattern matching, keyword arguments, and endless method definitions. The Ruby version requirement is updated from 2.7 to 3.2, necessitating a major version bump to 5.0.0.
Key Changes:
- Refactored
Unit#initializeto use pattern matching withcase/insyntax for cleaner type handling - Updated
Configuration#initializeto accept keyword arguments with sensible defaults - Modernized method definitions using Ruby 3.2+ features (endless methods, shorthand hash syntax, argument forwarding with
...)
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| ruby-units.gemspec | Updated minimum Ruby version requirement from 2.7 to 3.2 |
| lib/ruby_units/version.rb | Bumped version from 4.1.0 to 5.0.0 for major release |
| lib/ruby_units/configuration.rb | Refactored initialize to use keyword arguments (separator, format) with forward-compatible **_options |
| spec/ruby_units/configuration_spec.rb | Added comprehensive tests for new Configuration initialization with keyword arguments |
| lib/ruby_units/unit.rb | Refactored initialize using pattern matching; updated multiple methods (abs, ceil, floor, round, truncate, succ, pred) to use keyword argument syntax and argument forwarding; applied shorthand hash syntax in eliminate_terms |
| lib/ruby_units/definition.rb | Converted prefix? and unity? methods to endless method definitions |
| README.md | Added Ruby 3.2+ requirement notice and keyword arguments usage example |
| Gemfile.qlty | New file for qlty-specific development gems (rubocop, rubocop-rake, rubocop-rspec) |
| Gemfile | Moved rubocop gems to Gemfile.qlty and added eval_gemfile to load them |
| .qlty/qlty.toml | Added rubocop and reek plugin configurations |
| .github/workflows/tests.yml | Removed commented-out CodeClimate coverage code |
| Gemfile.lock | Updated dependency versions and removed some platform-specific entries; changed bundler version from 4.0.2 to 2.7.2 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| unit = object.to_unit # convert any object using object.to_s | ||
| unit = Unit.new('1/4 cup') # Rational number | ||
| unit = Unit.new('1+1i mm') # Complex Number | ||
| unit = Unit.new(scalar: 1.5, numerator: ["<meter>"], denominator: ["<second>"]) # keyword arguments |
Copilot
AI
Dec 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README shows an example of using keyword arguments to create a Unit (line 57), but this constructor pattern lacks test coverage. Consider adding a test to verify that Unit.new(scalar: 1.5, numerator: ["<meter>"], denominator: ["<second>"]) works as expected and produces the correct unit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback
Co-authored-by: olbrich <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Refactor methods to enhance readability and clarity by adopting keyword arguments and pattern matching. Update the required Ruby version to 3.2 and ensure configuration initialization aligns with these changes. Additionally, address minor quality fixes.
This will introduce a major version bump due to the requirement for ruby 3.2+