The Hidden Costs of Metaprogramming

Metaprogramming sounds like a very fancy word, but is it any good? It can be useful, but many people don’t realize that using metaprogramming has some costs. Just so we are on the same page… What is metaprogramming exactly? I define metaprogramming as using any method that: Alters the structure of your code (like define_method) … Read more

There Is No Magic in Ruby

You may have heard (or even said yourself) that Rails / Ruby has too much magic… But where does that idea come from? What is Rails magic exactly? And what can you do to dispel that magic? Here’s what I think: When something feels like magic it’s because there is something you don’t know, there … Read more

How to Use Struct & OpenStruct in Ruby

What is a Struct in Ruby? A struct is a built-in Ruby class, it’s used to create new classes which produce value objects. A value object is used to store related attributes together. Here’s an example: A Point with two coordinates (x & y). You can represent this data in many different ways. Like: An … Read more

Practical Graph Theory in Ruby

This is the next installment in the “Practical Computer Science” series, where you will learn how to apply classic computer science concepts to solve real problems using Ruby. Today we are going to talk about Graph Theory. You may have heard about binary trees, they look like this: The thing is that a binary tree … Read more