Main Content

Object Oriented Ruby - new examples

Archive - Originally posted on "The Horse's Mouth" - 2010-02-03 23:01:43 - Graham Ellis

We had an "object oriented Ruby" morning on today's course. "But everything's an object in Ruby" you'll tell me and you're sort of right (we could argue about what symbols and code blocks are), but there are certain elements of object orientation which require specific coverage.

Here are links to three examples:

[link] - a straightforward example of a class definintion, no inheritance, nothing fancy (thout it does have an attribute accessor)

[link] - a demonstration that shows inheritance, embedding of classes within a module, static variable and methods, operator overloading, a singleton method and much more. There are plenty of comments in the source code of this example.

[link] - showing the difference between object and class (dymanic and static) variables.

The following new examples have also been added in other areas:

[link] - command line parameters to a Ruby program

[link] - BEGIN and END blocks, and autosplit

[link] - a comparison of symbols and strings in Ruby

[link] Commenting a regular expression in Ruby