An introduction to modules : Part 1

Almost every languages have variables, constants, classes and objects… but who knew about modules before Ruby was invented? A ruby module is not that easy to define because it can serve two different purposes. If we introduce the word Mixin in our definition, we’re diving into the more complex side of what modules are. Today, […]

Continue reading →

Playing with blocks : Part 2

In the first part, I tried to cover the basics of code blocks. Now, we’re going to talk about : Code blocks and scope A code block is a closure Oh no… not another definition of a closure? Yes, but I promise I will be quick. First, to understand what a closure is we have […]

Continue reading →

Playing with blocks : Part 1

A while back, I wrote an introduction on code blocks. So if you’re not sure what they are, you should read it first. Something I find interesting with code blocks is that they create the illusion of being executed at the moment they are written. It’s easy to get fooled, because when you look at […]

Continue reading →

Diving into ruby object model : Part 2

Understanding the “chain” In my last article, I explained where the various elements of an object were located. Now it’s time to understand what happens at run time when you write the following : obj.my_instance_method Ahh… A method call! Ruby knows what to do in this situation. Remember that inside “obj” resides a reference to […]

Continue reading →

Diving into ruby object model : Part 1

So far I’ve talked about how everything was an object in ruby, even classes. I also wrote an article explaining what were the most important steps to follow when trying to understand ruby classes and objects. This wasn’t a bad idea, but it was a rather simplistic view. I think we’re ready to dive into […]

Continue reading →

Use self explicitly

I like to remind myself that a method never floats in the air and that it is always contained into an object. That’s why I prefer to specify a receiver before the name of a method… no wonder if I’m outside the object or inside the object.

Continue reading →