Bird
0
0

Which of the following is the correct way to create an array in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Arrays
Which of the following is the correct way to create an array in Ruby?
Aarray = [1, 2, 3]
Barray = (1, 2, 3)
Carray = {1, 2, 3}
Darray = <1, 2, 3>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby array syntax

    Arrays in Ruby are created using square brackets [] with items separated by commas.
  2. Step 2: Check each option's syntax

    Only array = [1, 2, 3] uses square brackets correctly; others use parentheses, braces, or angle brackets which are invalid for arrays.
  3. Final Answer:

    array = [1, 2, 3] -> Option A
  4. Quick Check:

    Arrays use [] brackets [OK]
Quick Trick: Use square brackets [] to create arrays [OK]
Common Mistakes:
  • Using parentheses instead of brackets
  • Confusing arrays with hashes (curly braces)
  • Using angle brackets which are invalid

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes