Slide 36
Slide 36 text
require "active_support"
ActiveSupport::Notifications.subscribe("pony:created") do |name, payload|
puts "Pony #{payload[:id]} has been created!"
end
ActiveSupport::Notifications.subscribe(%r{pony}) do |name, payload|
puts "A pony event happend: #{name}, #{payload.inspect}"
end
ActiveSupport::Notifications.publish("pony:created", :id => 42)
ActiveSupport::Notifications.publish("pony:updated", :id => 42)
# Pony 42 has been created!
# A pony event happend: pony:created, {:id => 42}
# A pony event happend: pony:updated, {:id => 42}