Bird
0
0

You want to create a local variable to store a user's age in Ruby. Which of these variable names follows best naming conventions and is clear to other programmers?

hard📝 Application Q15 of 15
Ruby - Variables and Data Types
You want to create a local variable to store a user's age in Ruby. Which of these variable names follows best naming conventions and is clear to other programmers?
AUserAge
BuserAge
Cuser-age
Duser_age
Step-by-Step Solution
Solution:
  1. Step 1: Check Ruby naming conventions for local variables

    Local variables should start with lowercase letters or underscores and use underscores to separate words for clarity.
  2. Step 2: Evaluate each option for clarity and convention

    'user_age' uses lowercase and underscores, making it clear and conventional. 'UserAge' starts uppercase (looks like constant), 'user-age' has invalid hyphen, 'userAge' uses camelCase which is less common in Ruby.
  3. Final Answer:

    user_age -> Option D
  4. Quick Check:

    Use lowercase with underscores for clear local variables [OK]
Quick Trick: Use lowercase and underscores for clear Ruby local variables [OK]
Common Mistakes:
  • Using camelCase instead of snake_case
  • Starting variable names with uppercase letters
  • Using hyphens in variable names

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes