Ruby - ArraysWhat does Array.new(3, 'a') produce in Ruby?AErrorB['a', 'b', 'c']C['a']D['a', 'a', 'a']Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Array.new with default valueArray.new(3, 'a') creates an array of size 3 where each element is the same object 'a'.Step 2: Confirm outputThe array will be ['a', 'a', 'a'] as all elements reference the same string.Final Answer:['a', 'a', 'a'] -> Option DQuick Check:Array.new with default value repeats that value [OK]Quick Trick: Array.new(size, val) repeats val in all elements [OK]Common Mistakes:MISTAKESExpecting different elementsThinking it creates copies instead of referencesConfusing with block form
Master "Arrays" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Control Flow - Inline if and unless (modifier form) - Quiz 15hard Hashes - Hash as named parameters pattern - Quiz 8hard Hashes - Merge and update methods - Quiz 6medium Loops and Iteration - Times method for counted repetition - Quiz 3easy Loops and Iteration - Upto and downto methods - Quiz 7medium Methods - Parameters with default values - Quiz 5medium Methods - Method naming conventions (? and ! suffixes) - Quiz 14medium Operators and Expressions - Conditional assignment (||=) - Quiz 11easy Operators and Expressions - Why operators are methods in Ruby - Quiz 8hard Variables and Data Types - Type checking with .class and .is_a? - Quiz 7medium