Ruby - HashesWhich of the following is a disadvantage of using string keys instead of symbol keys in Ruby hashes?AString keys are immutable and cannot be changed.BString keys are faster to compare than symbol keys.CString keys automatically convert to symbols internally.DString keys consume more memory when reused multiple times.Check Answer
Step-by-Step SolutionSolution:Step 1: Analyze string key behaviorString keys are mutable and each instance is a separate object, so reusing the same string key creates multiple objects.Step 2: Understand memory impactThis leads to higher memory consumption compared to symbols, which are single immutable objects.Final Answer:String keys consume more memory when reused multiple times. -> Option DQuick Check:String keys memory usage = C [OK]Quick Trick: Strings use more memory if repeated as keys; symbols don't [OK]Common Mistakes:Confusing immutability of strings and symbolsAssuming string keys convert to symbols automaticallyBelieving string keys are always faster
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