Rails custom PORO object callbacks

Edit
equivalent Web Development
Public
Rails
callbacks
require 'active_model'


class Aaa
  extend ActiveModel::Callbacks

   # This will provide all three standard callbacks (before, around and after) for both the :create and :update methods
   define_model_callbacks :create # , :update

  def create
    run_callbacks :create do
      puts "Running create action"
    end
  end
end


class Bbb < Aaa
  before_create :foo
  after_create :bar

  def foo
    puts "foo called"
  end

  def bar
    puts "bar called"
  end
end

Bbb.new.create
# foo called
# Running create action
# bar called
end

MyProcess.new.create

# foo called
# Running create action
# bar called


example 2 - initialization example


class Viki
  extend ActiveModel::Callbacks
  define_model_callbacks :initialize, only: :after

  def initialize
    puts "Viki initialized"

    run_callbacks :initialize
  end
end

Viki.new
# Viki initialized

class Niki < Viki
  after_initialize :say_hi

  def say_hi
    puts "Hi from Niki!"
  end
end

Niki.new
# Viki initialized
# Hi from Niki!