Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/trigger.rb
Overview
Allows the declaration of events to be triggered.
Example:
class User < Person
def save
...
end
end
user = User.new
user.before(:save) { puts "Saving user..." }
user.after(:save) { puts "User saved." }
user.save
The block yields the object itself, so it’s possible to construct callbacks like this:
user.before :save do |u|
u.encrypt_password!
end