Predefined method chains

Predefined method chains

Ruby core library has many methods that accept names of other methods to do their job. Examples are private, public, private_class_method, module_function etc. Many gem also incorporate this approach in their codebase. Memery example:


carbon.now.sh

See this method that deals with result. Let's try to do something similar.

The problem we are going to address is to run validations on new ActiveRecord object. We call it verify


carbon.now.sh

Then we need to add custom validator for that. It should accept multiple objects and copy errors.


carbon.now.sh

Then we can do the following


Looks a bit strange, but compact )))



To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics