I have been given an exercise to write code for rails like before_filter
an开发者_如何学编程d after_filter
for a stand alone Ruby program. Not surprisingly I don't know how to write.
The simplest way to do this would be to use ActiveModel::Callbacks (you can require ActiveModel by itself outside of Rails), then you get all the niceness without having to mess about implementing it yourself.
I guess you just started learning rails. Go through the filters section of this link
http://guides.rubyonrails.org/action_controller_overview.html
It will be definitely good for your learning curve.
This question, I think, has the answer to your question:
How to implement a "callback" in Ruby?
精彩评论