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?
def show
  score = 7
  Score = 15
  puts score
end
show
A15
B7
C22
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand variable scope and case sensitivity

    In Ruby, local variables start with lowercase letters, constants start with uppercase letters.
  2. Step 2: Identify which variable is printed

    The method prints score (lowercase), which is 7. Score (uppercase) is a constant and not used in puts.
  3. Final Answer:

    7 -> Option B
  4. Quick Check:

    Local variable printed, not constant [OK]
Quick Trick: Local vars are case-sensitive and distinct from constants [OK]
Common Mistakes:
MISTAKES
  • Confusing constants with local variables
  • Assuming case-insensitive variable names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes