The `extended` callback
Just like included
which is a callback for include
, there is a callback for extend
and it is appropriately called extended
.
We'll breeze through it using a simple example:
Just like included
which is a callback for include
, there is a callback for extend
and it is appropriately called extended
.
We'll breeze through it using a simple example:
Object Oriented programming is fundamentally about grouping data and its related behaviour together. We call the data the 'state' of the object and any logic related to the state as the 'behaviour' of the object.
It is also possible (but not advisable) to write non-object oriented code in Ruby by avoiding creation of objects and instead relying on independent methods. Ruby's Math module is an example of a collection of such methods. This is how you can define and use a similar module:
A quick drill before we move on. In the following exercise you have to define a static method square
in the module Math
. It should obviously return the square of the number passed to it. Alright, jump right in: