Ruby - HashesWhich of the following hash definitions will cause a syntax error in Ruby?A{ name => "Bob", age => 25 }B{ :name => "Bob", :age => 25 }C{ "name" => "Bob", "age" => 25 }D{ name: "Bob", age: 25 }Check Answer
Step-by-Step SolutionSolution:Step 1: Review valid key syntaxSymbol keys can be written as :name => or name:. String keys must be quoted and use rocket syntax.Step 2: Identify invalid syntax{ name => "Bob", age => 25 } uses bare words as keys without colon or rocket, which is invalid and causes syntax error.Final Answer:SyntaxError -> Option AQuick Check:Bare words as keys need colon or rocket [OK]Quick Trick: Keys must be symbols with colon or strings with quotes and rocket [OK]Common Mistakes:MISTAKESUsing bare words as keys without colon or rocketMixing string keys without quotesConfusing colon placement for symbols
Master "Hashes" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Why arrays are fundamental in Ruby - Quiz 2easy Arrays - Accessing elements (indexing, first, last) - Quiz 10hard Arrays - Array slicing and ranges - Quiz 14medium Hashes - Hash as named parameters pattern - Quiz 3easy Loops and Iteration - Why Ruby prefers iterators over loops - Quiz 8hard Methods - Method declaration with def - Quiz 13medium Operators and Expressions - Range operators (.. and ...) - Quiz 8hard Operators and Expressions - Range operators (.. and ...) - Quiz 7medium Ruby Basics and Runtime - Puts, print, and p output differences - Quiz 12easy Variables and Data Types - Dynamic typing vs strong typing - Quiz 15hard