Sunday, March 11, 2007

Structured Freedom provided by Rails

You’re in charge of naming and writing the methods, but Rails provides an infrastructure that rationalizes and pre-systematizes the code for you.

An example of “structured freedom” are the method hooks available to you in your model definition files. A method hook is a method that you may, but aren’t obliged to, write; and if you do write it, it’s automatically called at a predefined point during program execution.
For example, if you write a method called before_create in one of your model files, then that method will be called automatically every time a database record corresponding to an instance of that model is created. This allows you to gatekeep the data in an orderly fashion and to manage your database at a low level while still writing everything in Ruby.

No comments: