Ruby - ArraysWhich method creates an array with 5 nil elements in Ruby?AArray.new(5)BArray[5]C[5].newDArray.create(5)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Array.new behaviorArray.new(5) creates an array with 5 elements, all set to nil by default.Step 2: Check other optionsArray[5] creates an array with one element 5, [5].new and Array.create(5) are invalid syntax.Final Answer:Array.new(5) -> Option AQuick Check:Array creation with nil elements = Array.new(5) [OK]Quick Trick: Use Array.new(size) for nil-filled arrays [OK]Common Mistakes:Using Array[5] creates single element arrayTrying invalid methods like Array.createConfusing array literal with constructor
Master "Arrays" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Compact for removing nil values - Quiz 7medium Control Flow - If, elsif, else statements - Quiz 4medium Hashes - Dig method for nested access - Quiz 13medium Methods - Variable-length arguments (*args) - Quiz 6medium Methods - Implicit return (last expression) - Quiz 8hard Operators and Expressions - Conditional assignment (||=) - Quiz 5medium Ruby Basics and Runtime - How Ruby interprets code at runtime - Quiz 14medium Ruby Basics and Runtime - Running scripts with ruby command - Quiz 8hard Ruby Basics and Runtime - What is Ruby - Quiz 10hard Variables and Data Types - Integer and Float number types - Quiz 1easy