Bird
0
0

What does the Ruby method p do differently compared to puts?

easy📝 Conceptual Q2 of 15
Ruby - Basics and Runtime
What does the Ruby method p do differently compared to puts?
APrints without newline
BPrints the object's inspect string with newline
CPrints only numbers
DPrints without quotes
Step-by-Step Solution
Solution:
  1. Step 1: Understand p method output

    p outputs the object using its inspect method, showing quotes for strings and adding a newline.
  2. Step 2: Compare with puts

    puts outputs the string without quotes and adds a newline.
  3. Final Answer:

    Prints the object's inspect string with newline -> Option B
  4. Quick Check:

    p shows inspect output with newline = D [OK]
Quick Trick: p shows quotes and newline, puts does not [OK]
Common Mistakes:
  • Thinking p prints without newline
  • Confusing p with print
  • Assuming p removes quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes