Ruby - Variables and Data TypesIdentify the error in this Ruby code:sym = :hello sym[0] = 'H'ASymbols cannot be indexed or modified.BSyntax error due to missing quotes.CNo error; symbol is mutable.DError because 'H' is not a symbol.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand symbol immutabilitySymbols are immutable and do not support indexing or modification.Step 2: Analyze code behaviorTrying to assign to sym[0] causes an error because symbols cannot be changed.Final Answer:Symbols cannot be indexed or modified. -> Option AQuick Check:Symbol immutability error = A [OK]Quick Trick: Symbols cannot be changed or indexed like strings [OK]Common Mistakes:Trying to modify symbols like stringsAssuming symbols support indexingConfusing symbol immutability with string mutability
Master "Variables and Data Types" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Why arrays are fundamental in Ruby - Quiz 3easy Control Flow - Guard clauses pattern - Quiz 13medium Control Flow - Guard clauses pattern - Quiz 14medium Control Flow - Guard clauses pattern - Quiz 15hard Hashes - Merge and update methods - Quiz 11easy Methods - Keyword arguments - Quiz 11easy Operators and Expressions - Arithmetic operators - Quiz 12easy Ruby Basics and Runtime - How Ruby interprets code at runtime - Quiz 9hard Ruby Basics and Runtime - Comments and documentation - Quiz 12easy Variables and Data Types - Nil as the absence of value - Quiz 13medium