DEV Community

Jokūbas Pučinskas
Jokūbas Pučinskas

Posted on

Callbacky - bring callbacks to simple Ruby objects

Hey folks! 👋

I just released a tiny Ruby gem called callbacky that brings declarative lifecycle callbacks (like before and after) to your plain Ruby objects — no Rails dependency required!
🚀 Why?

Sometimes you need a clean way to separate setup, teardown, or side-effects from core logic — like service objects, workers, or POROs. Inspired by Rails-style callbacks, Callbacky gives you a lightweight way to do this with methods, procs, or blocks.

✨ Features

Define before / after callbacks per lifecycle event (e.g., :init)

Supports method names, lambdas, or inline blocks

Chainable and extensible

Works with plain Ruby — no magic, no monkey patches
Enter fullscreen mode Exit fullscreen mode

💡 Usage

class MyService
  include Callbacky

  callbacky :before, :init, :prepare
  callbacky :after, :init, ->(obj) { obj.log_done }

  callbacky :after, :init do |instance|
    instance.notify!
  end

  def initialize
    callbacky_init do
      puts "Doing work..."
    end
  end

  def prepare    = puts "Preparing..."
  def log_done   = puts "Logging done"
  def notify!    = puts "Notifying"
end
Enter fullscreen mode Exit fullscreen mode

🛠 Open Source & Contributions Welcome

Check it out on GitHub 👉 github.com/pucinsk/callbacky
If you find it useful or have suggestions, I’d love your feedback and PRs!

Top comments (0)