Skip to content

Add Unit#value_in for bare-value conversion#37

Merged
nertzy merged 1 commit into
minad:masterfrom
nertzy:value-in
Jul 24, 2026
Merged

Add Unit#value_in for bare-value conversion#37
nertzy merged 1 commit into
minad:masterfrom
nertzy:value-in

Conversation

@nertzy

@nertzy nertzy commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Unit#in returns a converted Unit and Unit#in! raises on a dimensionally incompatible target, but neither yields the raw number in the requested unit without a caller peeling off #value by hand.

Unit#value_in(unit) converts via #in! and returns the bare numeric value, so an incompatible unit raises TypeError rather than handing back a coerced number with residual dimensions.

Unit(1, "kilometer").value_in("meter")       # => 1000
Unit(1, "kilometer/hour").value_in("meter/second")  # => (5/18)
Unit(1, "meter").value_in("second")          # raises TypeError

@nertzy nertzy self-assigned this Jul 24, 2026
Unit#in returns a converted Unit and Unit#in! raises on a dimensionally
incompatible target, but neither yields the raw number in the requested
unit without a caller peeling off #value by hand.

Add Unit#value_in(unit), which converts via #in! and returns the bare
numeric value. An incompatible unit therefore raises TypeError rather
than handing back a coerced number with residual dimensions.
@nertzy
nertzy merged commit ba06900 into minad:master Jul 24, 2026
4 checks passed
@nertzy
nertzy deleted the value-in branch July 24, 2026 16:30
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