Bird
0
0

How can you print each element of an array with quotes and a newline in Ruby using p inside a loop?

hard📝 Application Q9 of 15
Ruby - Basics and Runtime
How can you print each element of an array with quotes and a newline in Ruby using p inside a loop?
Ap array.each { |e| e }
Barray.each { |e| p e }
Cputs array.each { |e| p e }
Dprint array.each { |e| p e }
Step-by-Step Solution
Solution:
  1. Step 1: Understand the goal

    Print each element with quotes and newline, so use p on each element.
  2. Step 2: Analyze options

    array.each { |e| p e } calls p on each element, printing with quotes and newline; other options misuse p or combine methods incorrectly.
  3. Final Answer:

    array.each { |e| p e } -> Option B
  4. Quick Check:

    Use p inside each loop for quoted output = A [OK]
Quick Trick: Use p inside each to print elements with quotes [OK]
Common Mistakes:
  • Calling p on entire each block
  • Using puts with p incorrectly
  • Using print with each block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes