Bird
0
0

Which of the following variable names is valid for a local variable in Ruby?

easy📝 Conceptual Q1 of 15
Ruby - Variables and Data Types
Which of the following variable names is valid for a local variable in Ruby?
A_tempValue
B2ndValue
CUser-Name
DTotal$
Step-by-Step Solution
Solution:
  1. Step 1: Check variable naming rules

    Local variables in Ruby must start with a lowercase letter or underscore and can contain letters, digits, and underscores.
  2. Step 2: Analyze each option

    _tempValue starts with an underscore and contains letters, valid.
    2ndValue starts with a digit, invalid.
    User-Name contains a hyphen, invalid.
    Total$ contains a dollar sign, invalid.
  3. Final Answer:

    _tempValue -> Option A
  4. Quick Check:

    Starts with underscore, no invalid characters [OK]
Quick Trick: Local vars start with lowercase or underscore [OK]
Common Mistakes:
MISTAKES
  • Starting variable names with digits
  • Using special characters like hyphens or dollar signs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes