|
Data Structures and Algorithms
with Object-Oriented Design Patterns in Ruby |
The initialize method
of a class is special.
The purpose of a initialize method is to initialize an object.
The initialize method is invoked
whenever a new instance of a class is created.
The initialize method of the Complex class
is defined in Program
.
Consider the following statement:
i = Complex.new(0, 1)The effect of this statement is is to create a new object instance of the Complex class and then to invoke the initialize method on that object instance. Finally, the variable i is made to refer to the new Complex object instance.