Repository navigation
Add Numeric/Integer/Float #numerator and #denominator - #449
Merged
Merged
Conversation
#numerator and #denominator were undefined on Integer and Float (NoMethodError).
They are now defined in the prelude:
- Numeric#numerator / #denominator delegate to those of #to_r, covering any
Numeric subclass that defines #to_r;
- Integer overrides them to return self and 1 directly (Bignum included);
- Float uses the numerator/denominator of its exact rational value when finite,
and — since Infinity and NaN have no rational form — returns the Float itself
as the numerator and 1 as the denominator, matching MRI.
Verified against ruby 4.0.6. Full package coverage stays at 100.0% (the frozen
prelude was regenerated). Zero-regression rubyspec sweep; core/float/numerator
0 -> 5, core/float/denominator 0 -> 3, core/integer/{numerator,denominator}
0 -> 1 each, core/numeric/{numerator,denominator} 0 -> 1 each (the one remaining
error in each numeric spec is a spec_helper mock_numeric limitation — the shim
makes a plain mock rather than a Numeric subclass — not the method).
Co-Authored-By: Claude Opus 4.8 <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.
#numeratorand#denominatorwere undefined on Integer and Float(
NoMethodError). They are now defined in the prelude:Numeric#numerator/#denominatordelegate to those of#to_r, covering anyNumeric subclass that defines
#to_r;selfand1directly (Bignum included);and — since Infinity and NaN have no rational form — returns the Float itself
as the numerator and
1as the denominator, matching MRI.Verified against ruby 4.0.6. Full package coverage stays at 100.0% (the
frozen prelude was regenerated). Zero-regression rubyspec sweep;
core/float/numerator0 → 5,core/float/denominator0 → 3,core/integer/{numerator,denominator}0 → 1 each,core/numeric/{numerator,denominator}0 → 1 each (the one remaining error ineach numeric spec is a
spec_helpermock_numericlimitation — the shim makes aplain mock rather than a Numeric subclass — not the method).
🤖 Generated with Claude Code