Ruby - Variables and Data TypesWhy does Ruby return an Integer when dividing two integers but a Float when dividing an Integer by a Float?ARuby always returns Integer regardless of operand types.BRuby converts all numbers to strings before division.CRuby performs integer division if both operands are integers, else float division.DRuby throws an error if operands are different types.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand Ruby division rulesWhen both operands are integers, Ruby performs integer division, truncating decimals.Step 2: Mixed type division behaviorIf either operand is a float, Ruby performs float division and returns a float result.Final Answer:Ruby performs integer division if both operands are integers, else float division. -> Option CQuick Check:Division type depends on operand types [OK]Quick Trick: Division result type depends on operand types [OK]Common Mistakes:MISTAKESThinking Ruby always returns IntegerAssuming automatic string conversionExpecting error on mixed types
Master "Variables and Data Types" in Ruby9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Ruby Quizzes Arrays - Array methods (length, include?, flatten) - Quiz 1easy Arrays - Array methods (length, include?, flatten) - Quiz 2easy Hashes - Hash creation with symbols and strings - Quiz 5medium Hashes - Hash creation with symbols and strings - Quiz 8hard Hashes - Hash as named parameters pattern - Quiz 3easy Loops and Iteration - Times method for counted repetition - Quiz 10hard Loops and Iteration - Loop method for infinite loops - Quiz 12easy Loops and Iteration - For loop (rarely used in Ruby) - Quiz 4medium Operators and Expressions - Logical operators (&&, ||, !) - Quiz 11easy Operators and Expressions - Conditional assignment (||=) - Quiz 13medium