July 2011
Intermediate to advanced
400 pages
8h 46m
English
The game in 2adventure.rb will have two classes descending from Thing: the Treasure class and the Room class. The Treasure class adds a value attribute, which can be both read and written. Note that its initialize method calls its superclass in order to initialize the name and description attributes before initializing the new @value variable:
super( aName, aDescription ) @value = aValue
Here, if I had omitted the call to the superclass, the name and description attributes would never be initialized. This is because Treasure.initialize overrides Thing.initialize, so when a Treasure object is created, the code in Thing.initialize will not automatically be executed.
On the other hand, the Room class, which also descends ...
Read now
Unlock full access