Boolean Values
In this page:
Boolean Values
Ruby has true and false as the literal boolean values, both instances of their own classes (TrueClass and FalseClass). Comparison and logical operators produce these values directly. Ruby's boolean handling is simple, but its rules for what counts as "truthy" in a condition are broader than just true/false, covered in a later chapter.
Note: true and false are singleton objects in Ruby, each the sole instance of their own class.
Example: Boolean Values
is_active = true
is_admin = false
puts is_active.class
puts is_active && is_admin
puts 10 > 5
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: