Ruby - HashesHow do you correctly define a Ruby hash with symbol keys for :name and :age?A{ :name = 'Alice', :age = 30 }B{ 'name' => 'Alice', 'age' => 30 }C{ name: 'Alice', age: 30 }D{ name => 'Alice', age => 30 }Check Answer
Step-by-Step SolutionSolution:Step 1: Recognize symbol key syntaxRuby allows symbol keys using the syntax key: value without hash rockets.Step 2: Identify correct syntax{ name: 'Alice', age: 30 } uses symbol keys correctly with colon after the key name.Final Answer:{ name: 'Alice', age: 30 } -> Option CQuick Check:Symbol keys use colon after key name [OK]Quick Trick: Symbol keys use colon after key name [OK]Common Mistakes:MISTAKESUsing hash rockets with symbol keys incorrectlyUsing assignment (=) instead of colon (:)Using strings instead of symbols for keys
Master "Hashes" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array creation methods - Quiz 13medium Hashes - Dig method for nested access - Quiz 9hard Loops and Iteration - Times method for counted repetition - Quiz 15hard Loops and Iteration - Each as the primary iterator - Quiz 12easy Methods - Parameters with default values - Quiz 1easy Operators and Expressions - Truthy and falsy values (only nil and false are falsy) - Quiz 2easy Operators and Expressions - Ternary operator - Quiz 5medium Operators and Expressions - Ternary operator - Quiz 14medium String Operations - String slicing and indexing - Quiz 6medium Variables and Data Types - Local variables and naming conventions - Quiz 1easy