Bird
0
0

You want to print an array in Ruby so that the output shows quotes around strings. Which method should you use?

hard📝 Application Q8 of 15
Ruby - Basics and Runtime
You want to print an array in Ruby so that the output shows quotes around strings. Which method should you use?
Ap array
Bprint array
Cputs array.join(', ')
Dputs array
Step-by-Step Solution
Solution:
  1. Step 1: Understand output requirements

    Output should show quotes around strings.
  2. Step 2: Analyze methods

    p array outputs the array using inspect, showing quotes and the array structure on one line; puts array prints each element on a new line but without quotes; print array prints array without newline or quotes; puts array.join(', ') prints elements joined by comma without quotes.
  3. Step 3: Choose best fit

    Among the options, only p array shows quotes around strings.
  4. Final Answer:

    p array -> Option A
  5. Quick Check:

    Show quotes around strings = p [OK]
Quick Trick: Use p to see quotes and inspect output [OK]
Common Mistakes:
MISTAKES
  • Using puts for quotes
  • Assuming print adds newlines
  • Using join loses quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes