Skip to content

Add NoBacksies, for callbacks defined with blocks - #353

Merged
trans merged 1 commit into
mainfrom
feature/no-backsies
Nov 27, 2026
Merged

trans merged 1 commit into
mainfrom
feature/no-backsies

Conversation

@trans

@trans trans commented Nov 27, 2026

Copy link
Copy Markdown
Member

Brings the NoBacksies gem into Facets as a standard library, loaded with require 'facets/no_backsies'. It is not loaded by require 'facets'.

class Y
  include NoBacksies

  callback :method_added do |name|
    list << name
  end
end

What is the same

  • callback, callbacks, callback_express and callback_invoke, and the :once, :safe and :superless options.
  • NoBacksies::Callbacks and the module for each callback (NoBacksies::MethodAdded and so on).

What is different

  • include NoBacksies works, and is the same as including NoBacksies::Callbacks. The gem's README used it in an example, but there it did nothing.
  • The ten callback modules are generated from a list: 98 lines of code where the gem had about 200.
  • The callback methods stay private, as Ruby's are.
  • callback raises ArgumentError without a block.
  • callback_express with a block restores the setting when the block raises.

Fixes

  • super was called once for each callback, and not at all when no callback was defined or the callbacks were switched off. It is now called once after the callbacks, and alone when none run.
  • A class's callbacks were copied from its superclass the first time they were asked for, and the lists were shared, so a callback added in a subclass was added to the superclass too. A subclass now has its superclass's callbacks by lookup, and its own are its own.
  • With the gem loaded, a missing constant in a class that included it returned a value in place of raising NameError. const_missing now raises unless a callback supplies the constant, and returns what the callback returns. Its super is left for the callback to call, as the gem's documentation said.

24 tests. The whole suite passes (1568 tests; the 4 pending were pending before).

🤖 Generated with Claude Code

From the NoBacksies gem, as a standard library loaded with
require 'facets/no_backsies'. The ten callback modules are generated
from a list.

Fixed along the way: super was called once for each callback and not at
all when there was none; a subclass's callbacks were added to its
superclass's lists; a missing constant gave the list of callbacks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@trans
trans merged commit 8d0a647 into main Nov 27, 2026
16 checks passed
@trans
trans deleted the feature/no-backsies branch November 29, 2026 01:09
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