Recall & Review
beginner
What does
puts do in Ruby?puts prints the given object to the screen followed by a new line. It converts the object to a string if needed.Click to reveal answer
beginner
How is
print different from puts?print outputs the given object without adding a new line at the end, so the next output continues on the same line.Click to reveal answer
intermediate
What is special about
p in Ruby?p prints the object in a way that shows its internal structure, like quotes around strings and array brackets. It is useful for debugging.Click to reveal answer
beginner
Which method adds a new line automatically after printing?
puts adds a new line after printing. print does not add a new line automatically. p adds a new line because it calls inspect and then outputs with a new line.Click to reveal answer
intermediate
When should you use
p instead of puts or print?Use
p when you want to see the exact representation of an object, including quotes and special characters, which helps in debugging.Click to reveal answer
Which Ruby method adds a new line after printing?
✗ Incorrect
puts adds a new line after printing the output. p also adds a new line because it outputs the inspected object followed by a new line.What does
p "hello" output?✗ Incorrect
p shows the string with quotes, so it outputs "hello".Which method prints without adding a new line?
✗ Incorrect
print outputs without adding a new line.Which method is best for debugging to see object details?
✗ Incorrect
p shows the internal structure of objects, useful for debugging.What will
puts [1, 2, 3] output?✗ Incorrect
puts prints each element of the array on its own line.Explain the differences between
puts, print, and p in Ruby.Think about how each method handles new lines and object representation.
You got /4 concepts.
When would you choose to use
p instead of puts or print?Consider what helps you understand the data better during debugging.
You got /3 concepts.