Ruby - HashesWhy do Ruby hashes allow keys of many types (symbols, strings, numbers) but symbols are preferred?ASymbols are immutable and memory-efficient keysBStrings are faster than symbols as keysCNumbers cannot be used as hash keysDSymbols automatically convert to stringsCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand symbol propertiesSymbols are immutable and reused, so they save memory and speed up key comparisons.Step 2: Compare with strings and numbersStrings are mutable and create new objects, numbers can be keys but symbols are more efficient for identifiers.Final Answer:Symbols are immutable and memory-efficient keys -> Option AQuick Check:Symbols = efficient, immutable keys = A [OK]Quick Trick: Use symbols as keys for efficiency and immutability [OK]Common Mistakes:MISTAKESThinking strings are faster than symbolsBelieving numbers cannot be keysAssuming symbols convert to strings automatically
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