Chapter 8. References: Crossed Signals

image with no caption

Ever sent an email to the wrong contact? You probably had a hard time sorting out the confusion that ensued. Well, Ruby objects are just like those contacts in your address book, and calling methods on them is like sending messages to them. If your address book gets mixed up, it’s possible to send messages to the wrong object. This chapter will help you recognize the signs that this is happening, and help you get your programs running smoothly again.

Some confusing bugs

The word continues to spread—if someone has a Ruby problem, your company can solve it. And so people are showing up at your door with some unusual dilemmas...

image with no caption

This astronomer thinks he has a clever way to save some coding. Instead of typing my_star = CelestialBody.new and my_star.type = 'star' for every star he wants to create, he wants to just copy the original star and set a new name for it.

image with no caption

But the plan seems to be backfiring. All three of his CelestialBody instances are reporting that they have the same name!

The heap

The bug in the star catalog program stems from an underlying problem: the developer thinks he’s working with multiple objects, when actually he’s operating on the same ...

Get Head First Ruby now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.