Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby
next up previous index

initialize Method

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 gif.

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.


next up previous index

Bruno Copyright © 2004 by Bruno R. Preiss, P.Eng. All rights reserved.