The following code defines a class named codice_10. In addition to codice_11, the usual constructor to create new objects, it has two methods: one to override the codice_12 comparison operator (so codice_13 can sort by age) and the other to override the codice_14 method (so codice_15 can format its output). Here, codice_16 is an example of metaprogramming in Ruby: codice_17 defines getter and setter methods of instance variables, but codice_16 only getter methods. The last evaluated statement in a method is its return value, allowing the omission of an explicit codice_19 statement.

The preceding code prints three names in reverse age order:

codice_10 is a constant and is a reference to a codice_21 object.

Metaprogramming
Blocks and iterators
Classes
Exceptions