Skip to content

Teach the combinators from method_missing - #33

Merged
nz merged 3 commits into
mainfrom
feat/teaching-no-method-error
Aug 7, 2026
Merged

nz merged 3 commits into
mainfrom
feat/teaching-no-method-error

Conversation

@nz

@nz nz commented Aug 7, 2026

Copy link
Copy Markdown
Member

Fixes #18.

Some(5) + 1 now raises Errgonomic::UnwrappedAccessError whose 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 that unwrap!/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 existing rescue NoMethodError and Ruby-internal path keeps working. Verified: 5 + Some(1) still raises Ruby's standard coercion TypeError (the coerce probe checks respond_to? first), [*Some(1)] splats via to_a, to_ary/to_hash probes return false, string interpolation still hits the deliberate SerializeError.
  • respond_to_missing? defers to super — no lying about capabilities.
  • The message lists 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_missing stub 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.

lutzcc1
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
nz force-pushed the feat/teaching-no-method-error branch from 4a54f1b to 4e88626 Compare August 7, 2026 19:39
nz added 2 commits August 7, 2026 14:40
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
@nz
nz merged commit 9f74073 into main Aug 7, 2026
1 check passed
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.

Option: NoMethodError gives no route to the combinators (hurts agent usability)

2 participants