Ruby - HashesWhich of the following is a syntax error when creating a Ruby hash?A{ :age => 30, name: "Bob" }B{ age: 30 name: "Bob" }C{ "age" => 30, :name => "Bob" }D{ age: 30, "name" => "Bob" }Check Answer
Step-by-Step SolutionSolution:Step 1: Check commas between pairsRuby hashes require commas between key-value pairs. { age: 30 name: "Bob" } misses a comma between 30 and name:.Step 2: Validate other optionsOptions A, B, and C correctly separate pairs with commas and use valid syntax.Final Answer:{ age: 30 name: "Bob" } -> Option BQuick Check:Missing commas cause syntax errors [OK]Quick Trick: Always separate hash pairs with commas [OK]Common Mistakes:Omitting commas between pairsMixing symbol and string keys incorrectlyUsing invalid key syntax
Master "Hashes" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array slicing and ranges - Quiz 3easy Control Flow - Case/when statement - Quiz 13medium Hashes - Accessing and setting values - Quiz 1easy Methods - Bang methods (ending with !) - Quiz 12easy Methods - Why methods always return a value in Ruby - Quiz 12easy Operators and Expressions - Logical operators (&&, ||, !) - Quiz 15hard Ruby Basics and Runtime - Everything is an object mental model - Quiz 14medium String Operations - Heredoc syntax for multiline strings - Quiz 5medium Variables and Data Types - Integer and Float number types - Quiz 6medium Variables and Data Types - Local variables and naming conventions - Quiz 12easy