Changes

Jump to: navigation, search

Ruby Object Oriented Programming

5 bytes added, 12:54, 1 December 2007
Ruby Class Inheritance
== Ruby Class Inheritance ==
As we mentioned earlier in this chapter, Ruby support supports ''single inheritance''. This means that a subclass can be created which inherits all the variables and methods of another class. The subclass is then extended to add new methods or variables not available in the superclass.
One class inherits from another using the < character. Say, for example, that we want a new kind of BankAccount class. This class needs all the same variables and methods as our original class, but also needs the customer's phone number. To do this we simply inherit from ''BankAccount'' and add the new instance variable:

Navigation menu