Skip to content

Add the Bang notation; fix hashes taken for options - #4

Merged
trans merged 1 commit into
masterfrom
bang
Nov 23, 2026
Merged

trans merged 1 commit into
masterfrom
bang

Conversation

@trans

@trans trans commented Nov 23, 2026

Copy link
Copy Markdown
Member

Adds assay/bang, the Bang gem rebuilt on Assay's classes, following the sketch already in that project (work/ideas/assay-based).

require 'assay/bang'

10.kind_of!(Integer)     # InstanceAssay / KindAssay on failure
10.equal!(5 + 5)         # EqualAssay
10.not_equal!(20)
10.even!                 # no assay for it: Integer#even?, fails with Assertion
lambda{ raise ArgumentError }.raises!(ArgumentError)
  • A bang method Ruby doesn't know is resolved when called, through method_missing: first an assay class by name or operator, then the object's own foo?. Nothing is defined ahead of time, so assay classes added later are found and real bang methods (String#upcase!) are untouched.
  • respond_to? agrees with it.
  • Differences from the Bang gem: failures are assay classes where there is one, not Bang::Assertion; the query methods it added to Object (equal_to?, raises? and so on) are not carried over.

Bug fixed

A trailing Hash was always popped as options, so comparing two hashes raised ArgumentError in every notation:

{a: 1}.should.equal({a: 1})    # ArgumentError before

Only a Hash whose keys are all :message or :backtrace is options now, and the notations pass options explicitly.

Testing

rake on Ruby 3.4.9: 54 demos (355 steps) including the new demo/bang, 138 unit tests, adapter check, all passing.

🤖 Generated with Claude Code

assay/bang is the Bang gem rebuilt on Assay's classes, after the sketch
in that project's work/ideas/assay-based: x.equal!(y) fails with an
EqualAssay, and a query method Assay has no class for (10.even!) fails
with an Assertion. Methods are resolved when called, by method_missing,
so nothing is defined ahead of time.

A trailing Hash was always popped as options, so comparing two hashes
raised ArgumentError in every notation. Now only a Hash whose keys are
all :message or :backtrace is options, and the notations always pass
options explicitly.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit 669b61b into master Nov 23, 2026
14 checks 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.

1 participant