Ruby Compendium - Advanced Language Features

One of the best things about Ruby is that you’re not stuck with a single programming paradigm. Even though everything in Ruby is an object (thereby making it a fully object-oriented language), nothing forbids you to program procedurally, or even use typical functional constructs.

The beauty of this is that you can (and should) combine elements from different paradigms, resulting in very powerful and expressive code. What I really like about Ruby though is its inherent dynamic nature.

You have a very few constraints when coding:

  • you can open and close class definitions at will,
  • you are not constrained by object types
  • you can mix-in methods in multiple classes at the same time
  • you can write code that writes itself dynamically (this is commonly called metaprogramming)
  • you can easily create Domain-Specific Language to solve problems faster, with style
  • you can create and pass around blocks of code

All these things make the language very flexible and powerful. Do not overuse Ruby’s power: if your code starts to look like black magic, you’re probably going too far.