Bird
0
0

Which of the following is the correct way to assign a Boolean true value to a variable in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Variables and Data Types
Which of the following is the correct way to assign a Boolean true value to a variable in Ruby?
Aflag = True
Bflag = TRUE
Cflag = true
Dflag = "true"
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby's Boolean literals

    Ruby uses lowercase true and false as Boolean literals.
  2. Step 2: Check each option's syntax

    True and TRUE are invalid; "true" is a string, not Boolean.
  3. Final Answer:

    flag = true -> Option C
  4. Quick Check:

    Boolean true literal = true [OK]
Quick Trick: Boolean true is lowercase true in Ruby [OK]
Common Mistakes:
  • Using uppercase True or TRUE
  • Assigning string 'true' instead of Boolean
  • Syntax errors with capitalization

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes