Active Record classes can implement
validations in several ways. The highest level, easiest to read, and
recommended approach is to use the declarative validates_..._of
class methods (and validates_associated) documented below. These
are sufficient for most model validations.

Slightly lower level is validates_each.
It provides some of the same options as the purely declarative validation
methods, but like all the lower-level approaches it requires manually
adding to the errors collection when the record is invalid.

Calls to these methods add a validation method or block to the class.
Again, this approach is recommended only when the higher-level methods
documented below (validates_..._of and
validates_associated) are insufficient to handle the required
validation.

This can be done with a symbol pointing to a method:

class Comment<ActiveRecord::Basevalidate:must_be_friendsdef must_be_friendserrors.add_to_base("Must be friends to leave a comment")unlesscommenter.friend_of?(commentee)endend

Or with a block which is passed the current record to be validated:

class Comment<ActiveRecord::Basevalidatedo|comment|comment.must_be_friendsenddef must_be_friendserrors.add_to_base("Must be friends to leave a comment")unlesscommenter.friend_of?(commentee)endend