Printing Things

Learn another way to print something in Ruby.

We'll cover the following

Many exercises demonstrating Ruby basics include running a short program that outputs something to the terminal.

So far, we’ve mostly used the puts method to do that.

What can be used instead of puts?

However, there’s another method that’s even more useful when we’re trying to determine what a program is doing, why it’s doing it, and what might cause certain errors.

This is the p method. To understand p better, we’ll look at another method first, which is inspect.

The inspect method is available on any object in Ruby. It returns a string that’s a representation of the object itself—a representation that’s as close as possible to the code that we use to create the object.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy