Skip to content

Numeric: zero?, real, floor, ceil, round, truncate fallbacks - #469

Merged
tannevaled merged 1 commit into
mainfrom
feat/cluster39
Aug 27, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/cluster39

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

A Numeric subclass that defines only #to_f (and #<=>) inherited none of
these, so zero? / real / floor / ceil / round / truncate raised
NoMethodError — and #nonzero?, which dispatches through #zero?, broke with
it.

They now delegate the way MRI does: zero? is self == 0 (honouring a subclass's
own #== / #<=>), real returns self, and floor / ceil / round /
truncate operate on #to_f, forwarding the optional digits argument to Float.
Integer and Float keep their own overrides.

Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
ratchet floor rises 15800 → 15810 (core/numeric +6, zero regressions in a
deterministic per-file sweep).

🤖 Generated with Claude Code

A Numeric subclass that defines only #to_f (and #<=>) inherited none of these, so
zero? / real / floor / ceil / round / truncate raised NoMethodError (and #nonzero?,
which dispatches through #zero?, broke with it).

They now delegate the way MRI does: zero? is self == 0 (honouring a subclass's
own #== / #<=>), real returns self, and floor / ceil / round / truncate operate
on #to_f, forwarding the optional digits argument to Float. Integer and Float keep
their own overrides.

Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
floor rises 15800 -> 15810 (core/numeric +6).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 2395009 into main Aug 27, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/cluster39 branch August 27, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant