Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Variables and Data Types
What will be the output of this Ruby code?
user = 'Eve'
puts "Welcome, #{user}!"
puts 'Welcome, #{user}!'
AWelcome, Eve! Welcome, #{user}!
BWelcome, #{user}! Welcome, Eve!
CWelcome, Eve! Welcome, Eve!
DWelcome, #{user}! Welcome, #{user}!
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in Ruby

    Double-quoted strings allow interpolation, single-quoted do not.
  2. Step 2: Analyze the code

    "Welcome, #{user}!" will replace #{user} with 'Eve'. Single quotes will print the string literally.
  3. Final Answer:

    Welcome, Eve!\nWelcome, #{user}! -> Option A
  4. Quick Check:

    Double quotes interpolate, single quotes do not [OK]
Quick Trick: Double quotes interpolate variables, single quotes don't [OK]
Common Mistakes:
  • Assuming single quotes interpolate variables
  • Confusing output order
  • Thinking both strings behave the same

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes