Class, Module and Test Example
In the Sunday section, we created a small application that several students requested the final source for. It includes examples of:
- Class inheritance
- Raising and catching exceptions
- Using a module via include and extend
- Testing using Test::Unit
- Spreading code between multiple files
- Using method_missing to dynamically add methods
- How to tune a Ukulele for fun and profit
I tried to make use of as much of the last two lectures as possible. If you have any questions about how this works, or why things are done the way they are, feel free to comment below.
You can click here to downloaded the completed source code.
Run “ruby section.rb” to actually run the application. Edit this file as you see fit.
Run “ruby instrument_test.rb” to run the tests.