Ruby code can programmatically modify, at [[Run time (program lifecycle phase)|runtime]], aspects of its own structure that would be fixed in more rigid languages, such as class and method definitions. This sort of [[metaprogramming]] can be used to write more concise code and effectively extend the language.

For example, the following Ruby code generates new methods for the built-in codice_30 class, based on a list of colors. The methods wrap the contents of the string with an HTML tag styled with the respective color.

The generated methods could then be used like this:

To implement the equivalent in many other languages, the programmer would have to write each method (codice_31, codice_32, codice_33, etc.) separately.

Some other possible uses for Ruby metaprogramming include:

Metaprogramming
More examples
ବାହାର ଲିଙ୍କ
Blocks and iterators