Bird
0
0

What does the Ruby method unshift do to an array?

easy📝 Conceptual Q2 of 15
Ruby - Arrays
What does the Ruby method unshift do to an array?
ARemoves the last element
BAdds an element to the end
CRemoves the first element
DAdds an element to the beginning
Step-by-Step Solution
Solution:
  1. Step 1: Understand unshift behavior

    unshift adds one or more elements to the start of an array.
  2. Step 2: Compare with other methods

    push adds to the end, pop removes last, shift removes first.
  3. Final Answer:

    Adds an element to the beginning -> Option D
  4. Quick Check:

    Add to start = unshift [OK]
Quick Trick: unshift adds at front, push adds at end [OK]
Common Mistakes:
  • Mixing unshift with push
  • Thinking unshift removes elements
  • Confusing unshift with shift

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes