Consider this Ruby code snippet. What will it print?
x = 10 x = "hello" puts x
In Ruby, variables can hold any type and can change type.
Ruby is dynamically typed, so the variable x can hold an integer first, then a string. The last value assigned is printed.
What error will this Ruby code produce?
a = 5 b = "3" puts a + b
Ruby does not automatically convert between strings and numbers for addition.
Ruby is strongly typed, so adding an integer and a string without conversion causes a TypeError.
Choose the statement that correctly describes Ruby's typing.
Think about when types are checked and if implicit conversions happen.
Ruby checks types at runtime (dynamic typing) and does not allow implicit type coercion in operations (strong typing).
What will this Ruby code print?
def add(x, y) x + y end puts add(2, 3) puts add("2", "3") puts add(2, "3")
Consider how Ruby handles addition for integers and strings, and what happens when types differ.
Adding integers works (5). Adding strings concatenates ("23"). Adding integer and string causes TypeError.
Choose the best explanation for why Ruby raises a TypeError when adding an integer and a string.
Think about how Ruby treats types during operations and if it converts types automatically.
Ruby's strong typing means it forbids operations between incompatible types without explicit conversion, causing TypeError.