Bird
0
0

Why does arr.pop return the removed element, but arr.push(5) returns the array itself?

hard📝 Conceptual Q10 of 15
Ruby - Arrays
Why does arr.pop return the removed element, but arr.push(5) returns the array itself?
ABoth return updated array
Bpop returns array; push returns removed element
Cpop returns removed element; push returns updated array for chaining
DBoth return removed element
Step-by-Step Solution
Solution:
  1. Step 1: Understand pop return value

    pop removes and returns the last element removed from the array.
  2. Step 2: Understand push return value

    push adds element(s) and returns the updated array to allow method chaining.
  3. Final Answer:

    pop returns removed element; push returns updated array for chaining -> Option C
  4. Quick Check:

    pop returns element, push returns array [OK]
Quick Trick: pop returns element, push returns array for chaining [OK]
Common Mistakes:
  • Assuming both return same type
  • Confusing return values
  • Ignoring method chaining behavior

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes