Multiple choice technology programming languages

Which of the following will not result in error. x=10 y=20 a) puts x.to_s + "+" + y.to_s + "=" + (x+y).to_s b) puts "#{x} + #{y} = #{x + y}" c) puts x + y d) puts x

  1. a

  2. b

  3. c

  4. d

Reveal answer Fill a bubble to check yourself
A,B,C,D Correct answer
Explanation

All four options are valid Ruby. (a) explicitly converts to strings before concatenation. (b) uses string interpolation #{}. (c) prints the sum 30 (valid). (d) prints x=10 (valid). Ruby allows puts of any object, calling to_s automatically.