Skip to content

Conversation

@olbrich
Copy link
Owner

@olbrich olbrich commented Dec 26, 2025

Refactor the unit initialization for better clarity and structure. Additionally, update the Gemfile to include new dependencies and ensure compatibility with existing gems.

Rationale

Breaking Change: Hash Parameter Validation

The hash initialization API now strictly validates parameters:

# Previously accepted (might fail later or produce unexpected results)
RubyUnits::Unit.new(scalar: "invalid", numerator: "<meter>", denominator: "<second>")

# Now raises immediately
# ArgumentError: :scalar must be numeric
# ArgumentError: :numerator must be an Array<String>
# ArgumentError: :denominator must be an Array<String>

This is a breaking API change because:

  1. Code that passed invalid types will now fail with ArgumentError
  2. The failure happens earlier and with different error messages
  3. Even if this was unintentional usage, changing error behavior is a breaking change

Non-Breaking Changes (would be MINOR/PATCH)

All other changes are backward compatible:

  • ✅ Cache pollution prevention (bugfix)
  • ✅ Regex optimization (performance improvement)
  • ✅ Special format detection (internal improvement)
  • ✅ Code refactoring (internal structure)

@olbrich olbrich self-assigned this Dec 26, 2025
@olbrich olbrich marked this pull request as ready for review December 26, 2025 17:10
@olbrich olbrich added Minor add functionality in a backwards-compatible manner Major incompatible API changes and removed Minor add functionality in a backwards-compatible manner labels Dec 26, 2025
@olbrich olbrich merged commit 5c0af38 into master Dec 26, 2025
9 of 10 checks passed
@olbrich olbrich deleted the refactor-initialize branch December 26, 2025 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Major incompatible API changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants