Repository navigation
Document Option equality semantics; resolve the None == nil TODO - #35
Merged
Merged
Conversation
Cross-type == stays quietly false rather than raising: Rust rejects Some(5) == 5 at compile time, but Ruby compares heterogeneous operands pervasively (Array#include?, assertion diffs, dirty tracking), so raising from == would break innocent call sites. None() == nil stays false; the Rails shim's None#nil? compromise does not extend to equality. Point to opt == Some(x) and some_and? as the idioms. Closes #20.
nz
enabled auto-merge
August 7, 2026 18:32
This was referenced Aug 7, 2026
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.
Closes #20 as won't-fix-the-behavior, with the docs the issue asked for as the fallback.
The issue wants
Some(5) == 5to raiseTypeMismatchError. Declining the raise:==is called pervasively with heterogeneous operands in Ruby —[Some(1), "x"].include?(Some(1))callsSome(1) == "x",assert_equal 1, optdiffs across types, ActiveRecord dirty tracking compares old/new attribute values — and every other Ruby object answers cross-type==withfalse. A raise converts silent-wrong into loud-wrong at innocent call sites, which is the worse trade. The discoverability gap is instead covered by #33's teachingUnwrappedAccessErrorand #29's readableinspect, which make a mistyped comparison visible the moment anything touches the value.What this PR does:
TODO: does None == nil?— the answer is no,None() == nilstaysfalse.Noneis a value representing absence, not an absence Ruby can see. The Rails shim'sNone#nil? == trueis documented as an ActiveRecord compromise that equality deliberately does not follow (Document the ActiveRecord pragmatic compromises in ActiveRecordOptional #25 covers the compromise set).==doc comment with the rationale and the idioms (opt == Some(5),opt.some_and? { |v| v == 5 }), removing the stalestrict:sketch.No behavior change; the existing
==doctests already pin all six cases.