Repository navigation
Teach the combinators from method_missing - #33
Merged
Merged
Conversation
nz
enabled auto-merge
August 7, 2026 18:29
This was referenced Aug 7, 2026
lutzcc1
previously approved these changes
Aug 7, 2026
A bare NoMethodError on an Option or Result names no route forward, which pushes callers (human and agent alike) toward unwrap!. Raise UnwrappedAccessError instead: it names the receiver, states that containers do not forward to their inner value, lists the combinators by task, and marks unwrap!/expect! as test-only. Subclassing NoMethodError keeps every rescue path and Ruby-internal probe (coerce, to_ary, splat) working; respond_to_missing? stays honest. Fixes #18.
nz
force-pushed
the
feat/teaching-no-method-error
branch
from
August 7, 2026 19:39
4a54f1b to
4e88626
Compare
is_some, is_none, is_some_and, is_none_or (and the Result equivalents) delegate to the Ruby-idiomatic predicate via method_missing, printing a one-line redirect to stderr. The Rust spelling works for anyone porting Rust idioms, without adding un-Ruby-ish names to the advertised API; respond_to? answers true since the calls genuinely work. Fixes #24.
Accept Rust spellings of the predicates, with a nudge
lutzcc1
approved these changes
Aug 7, 2026
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.
Fixes #18.
Some(5) + 1now raisesErrgonomic::UnwrappedAccessErrorwhose message names the receiver (Some(5), via the new inspect from #29), states that containers don't forward to their inner value, lists the combinators grouped by task, and says explicitly thatunwrap!/expect!are for tests. Result gets the same treatment with its own combinator list.Design points, addressing the issue's cautions:
UnwrappedAccessError < NoMethodError, so every existingrescue NoMethodErrorand Ruby-internal path keeps working. Verified:5 + Some(1)still raises Ruby's standard coercionTypeError(thecoerceprobe checksrespond_to?first),[*Some(1)]splats viato_a,to_ary/to_hashprobes return false, string interpolation still hits the deliberateSerializeError.respond_to_missing?defers tosuper— no lying about capabilities.filter, which lands in Option#filter and #flatten #32; merge order between the two is harmless.This also answers the issue's archaeology question: the commented-out
method_missingstub raised a placeholder string with no name/message, which is presumably why it was reverted. It's replaced by this implementation.Specified as doctests (rescue-based, asserting the error class and
respond_to?honesty); full message content exercised by the doctest examples' execution.