Ruby - HashesWhich of the following is the shorthand way to 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 to be defined with the shorthand syntax: key: value, which is equivalent to :key => value.Step 2: Identify correct syntax{ name: 'Alice', age: 30 } uses the shorthand symbol key syntax correctly.Final Answer:{ name: 'Alice', age: 30 } -> Option AQuick Check:Symbol key shorthand syntax = B [OK]Quick Trick: Use key: value for symbol keys, not quotes for strings [OK]Common Mistakes:Using strings instead of symbols for keysOmitting colons for symbol keysUsing variables as keys without symbols
Master "Hashes" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Compact for removing nil values - Quiz 15hard Loops and Iteration - While loop - Quiz 8hard Loops and Iteration - Until loop - Quiz 12easy Loops and Iteration - Loop method for infinite loops - Quiz 10hard Methods - Parameters with default values - Quiz 8hard Methods - Keyword arguments - Quiz 12easy String Operations - String slicing and indexing - Quiz 3easy String Operations - Heredoc syntax for multiline strings - Quiz 6medium String Operations - String methods (upcase, downcase, strip) - Quiz 8hard Variables and Data Types - Type checking with .class and .is_a? - Quiz 12easy