Created
December 25, 2014 02:32
-
-
Save xifengzhu/56f236a1cf5a8405b4c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
require 'active_support/callbacks' | |
class Record | |
include ActiveSupport::Callbacks | |
define_callbacks :save | |
# define_callbacks :kill | |
def save | |
run_callbacks :save do | |
puts "- save" | |
end | |
end | |
set_callback :save, :before, :saving_message | |
def saving_message | |
puts "saving..." | |
return true | |
end | |
set_callback :save, :after do |object| | |
puts object | |
puts "saved" | |
end | |
# def kill | |
# run_callbacks :kill do | |
# puts "- kill" | |
# end | |
# end | |
# set_callback :kill, :before, :kill_message | |
# def kill_message | |
# puts "before kill....." | |
# end | |
end | |
person = Record.new | |
person.save | |
person.kill | |
# ---output--- | |
# saving... | |
# - save | |
# saved |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment