Bird
0
0

What does the each method return after iterating over an array in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Loops and Iteration
What does the each method return after iterating over an array in Ruby?
AThe original array itself
BA new array with modified elements
CThe last element of the array
DThe number of elements iterated
Step-by-Step Solution
Solution:
  1. Step 1: Understand the behavior of each method

    The each method in Ruby iterates over each element but does not change the original array or create a new one.
  2. Step 2: Identify the return value of each

    After iteration, each returns the original array it was called on.
  3. Final Answer:

    The original array itself -> Option A
  4. Quick Check:

    Return value of each = original array [OK]
Quick Trick: Remember: each returns the original collection [OK]
Common Mistakes:
  • Thinking it returns a new array
  • Assuming it returns the last element
  • Confusing with map method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes