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

Classes

 

A Ruby class  defines a data structure that contains instance attributes, instance methods, and nested classes. In Ruby the class of an object and the type of an object are synonymous. Every Ruby object has is a class (type) that is directly or indirectly derived from the Ruby Object class. The class (type) of an object determines what it is and how it can be manipulated. A class encapsulates data, operations, and semantics. This encapsulation is like a contract between the implementer of the class and the user of that class.

The class statement is what makes Ruby an object-oriented language. A Ruby class definition groups a set of values with a set of operations. Classes facilitate modularity and information hiding. The user of a class manipulates object instances of that class only through the methods provided by that class.

It is often the case that different classes possess common features. Different classes may share common values and they may perform the same operations. In Ruby such relationships are expressed using derivation and inheritance.




next up previous index

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