Ruby - ArraysWhich 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>Check Answer
Step-by-Step SolutionSolution:Step 1: Recall Ruby array syntaxArrays in Ruby are created using square brackets [] with items separated by commas.Step 2: Check each option's syntaxOnly array = [1, 2, 3] uses square brackets correctly; others use parentheses, braces, or angle brackets which are invalid for arrays.Final Answer:array = [1, 2, 3] -> Option AQuick Check:Arrays use [] brackets [OK]Quick Trick: Use square brackets [] to create arrays [OK]Common Mistakes:Using parentheses instead of bracketsConfusing arrays with hashes (curly braces)Using angle brackets which are invalid
Master "Arrays" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array modification (push, pop, shift, unshift) - Quiz 11easy Arrays - Accessing elements (indexing, first, last) - Quiz 11easy Control Flow - Inline if and unless (modifier form) - Quiz 6medium Hashes - Symbol keys vs string keys decision - Quiz 13medium Loops and Iteration - Break, next, and redo behavior - Quiz 1easy Loops and Iteration - Why Ruby prefers iterators over loops - Quiz 14medium Loops and Iteration - Why Ruby prefers iterators over loops - Quiz 10hard Methods - Parameters with default values - Quiz 9hard Operators and Expressions - Truthy and falsy values (only nil and false are falsy) - Quiz 14medium String Operations - Split and join methods - Quiz 12easy