Ruby - String OperationsWhich expression extracts the substring 'cat' from str = "concatenate"?Astr[-6, 3]Bstr[3, 3]Cstr[2..4]Dstr[4, 3]Check Answer
Step-by-Step SolutionSolution:Step 1: Locate 'cat' in 'concatenate'The substring 'cat' starts at index 3 (0-based): c(0)o(1)n(2)c(3)a(4)t(5)...Step 2: Use slicing with start index and lengthstr[3, 3] extracts 3 characters starting at index 3, which is 'cat'.Final Answer:str[3, 3] -> Option BQuick Check:Start index + length slicing = correct substring [OK]Quick Trick: Start index + length extracts substring [OK]Common Mistakes:Off-by-one error in start indexUsing range that includes wrong charactersConfusing negative index meaning
Master "String Operations" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Compact for removing nil values - Quiz 2easy Arrays - Array methods (length, include?, flatten) - Quiz 9hard Hashes - Default values for missing keys - Quiz 4medium Hashes - Default values for missing keys - Quiz 12easy Hashes - Hash creation with symbols and strings - Quiz 3easy Loops and Iteration - Loop method for infinite loops - Quiz 6medium Loops and Iteration - Upto and downto methods - Quiz 4medium Operators and Expressions - Why operators are methods in Ruby - Quiz 7medium String Operations - String freezing for immutability - Quiz 13medium Variables and Data Types - String interpolation with #{} - Quiz 3easy