...

/

Debugging Using the Output to the Console

Debugging Using the Output to the Console

Learn to debug a Ruby program using the output to our console.

The inspect method

This is one of the easiest and most efficient ways to debug a program.

puts something.inspect

We can implement the inspect method for every object in any part of a program. It then returns a string representation of the object. Here, we may ask why we need to use puts something.inspect while we could use puts something.

The answer is that inspect is more verbose, and its primary purpose is to inspect. For example, puts nil and puts "" statements return an empty output on the screen, while .inspect gives us a better idea of what the object is:

$ pry
> puts nil

> puts nil.inspect
nil
>
...