Use Instance Hooks for per-object callbacks
masterIf you need to add callbacks to a specific instance of a class without affecting the entire class, include Hooks::InstanceHooks. This allows you to call define_hook and callback methods (like after_dark) directly on an object instance.
class Cat
include Hooks
include Hooks::InstanceHooks
define_hook :after_dark
after_dark { "Chase mice" }
end
# Instance-specific extension
garfield = Cat.new
garfield.after_dark :sleep # Adds :sleep to this instance only
garfield.run_hook(:after_dark) # => ["Chase mice", :sleep]
# Adding a new hook to an instance
garfield.define_hook :before_six
garfield.before_six { puts "Early!" }