Bird
0
0

What will this Ruby code output?

medium📝 Predict Output Q5 of 15
Ruby - Functional Patterns in Ruby
What will this Ruby code output?
def concat(str1, str2)
  str1 + str2
end

result = concat("Hi, ", "Ruby!")
puts result
AError
BHi,
CRuby!
DHi, Ruby!
Step-by-Step Solution
Solution:
  1. Step 1: Analyze function behavior

    The function concatenates two strings using + operator.
  2. Step 2: Evaluate function call and output

    concat("Hi, ", "Ruby!") returns "Hi, Ruby!" which is printed by puts.
  3. Final Answer:

    Hi, Ruby! -> Option D
  4. Quick Check:

    Pure function returns combined string [OK]
Quick Trick: String + operator joins strings without side effects [OK]
Common Mistakes:
  • Expecting partial string output
  • Confusing concatenation with printing
  • Assuming error due to missing return keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes