Recall & Review
beginner
What is a local variable in Ruby?
A local variable is a variable that is defined within a method or block and can only be used inside that method or block. It is not accessible outside its scope.
Click to reveal answer
beginner
How do you name a local variable in Ruby?
Local variable names must start with a lowercase letter or an underscore (_), followed by letters, digits, or underscores. They cannot start with a capital letter or special characters.
Click to reveal answer
beginner
Why should you use meaningful names for local variables?
Meaningful names make your code easier to read and understand, like giving clear labels to boxes so you know what's inside without opening them.
Click to reveal answer
beginner
Which of these is a valid local variable name in Ruby? <br> A) myVar <br> B) _temp <br> C) 2ndValue <br> D) $globalVar
Both A) myVar and B) _temp are valid local variable names. C) 2ndValue is invalid because it starts with a digit. D) $globalVar is a global variable, not local.
Click to reveal answer
beginner
What happens if you try to use a local variable outside its method or block?
Ruby will raise an error or treat it as nil because the local variable does not exist outside its defined scope.
Click to reveal answer
Which character can a local variable name in Ruby start with?
✗ Incorrect
Local variable names must start with a lowercase letter or underscore.
What is the scope of a local variable in Ruby?
✗ Incorrect
Local variables are only accessible inside the method or block where they are defined.
Which of these is NOT a valid local variable name in Ruby?
✗ Incorrect
Variable names cannot start with a digit.
Why is it important to use meaningful names for local variables?
✗ Incorrect
Meaningful names help make code easier to read and understand.
What symbol indicates a global variable in Ruby, not a local variable?
✗ Incorrect
Global variables start with a dollar sign ($), local variables do not.
Explain what a local variable is and how you should name it in Ruby.
Think about where the variable can be used and how its name looks.
You got /3 concepts.
Why is it important to follow naming conventions for local variables in Ruby?
Consider how others read your code or how you read your own code later.
You got /3 concepts.