Bird
0
0

What will this Ruby code output?

medium📝 Predict Output Q5 of 15
Ruby - Ecosystem and Best Practices
What will this Ruby code output?
def greet_user(name)
  puts "Hello, #{name}!"
end

greet_user("Bob")
Agreet_user
BHello, name!
CHello, Bob!
DError: undefined method
Step-by-Step Solution
Solution:
  1. Step 1: Understand string interpolation in Ruby

    #{name} inside double quotes inserts the value of the variable name.
  2. Step 2: Trace the method call

    Calling greet_user("Bob") prints "Hello, Bob!".
  3. Final Answer:

    Hello, Bob! -> Option C
  4. Quick Check:

    String interpolation inserts variable = A [OK]
Quick Trick: Use #{var} inside double quotes to insert values [OK]
Common Mistakes:
  • Using single quotes which don't interpolate
  • Printing variable name literally
  • Expecting method name output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes