← Back to Ruby Course | Chapter 2: Variables & Types | Lesson 4 of 7

Boolean Values क्या हैं

Boolean values true और false हैं, एक light switch की तरह जो on या off है। Ruby इन्हें yes-or-no questions answer करने के लिए इस्तेमाल करता है।

In this page:

  1. Boolean Values
Syntax
ruby
flag = true
other = false
result = value1 > value2

Boolean Values

Ruby में literal boolean values की तरह true और false हैं, दोनों अपनी classes (TrueClass और FalseClass) के instances। Comparison और logical operators सीधे ये values produce करते हैं।

Ruby की boolean handling simple है, लेकिन एक condition में "truthy" क्या count होता है इसके rules सिर्फ true/false से broader हैं, एक बाद के chapter में cover किए गए।

Note: true और false Ruby में singleton objects हैं, हर एक अपनी class का sole instance।

उदाहरण: Boolean Values

markup
is_active = true
is_admin = false

puts is_active.class
puts is_active && is_admin
puts 10 > 5
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि 0 या एक empty string false होगी, जब Ruby में सिर्फ false और nil falsy हैं।
  2. True या TRUE लिखना, जिसे Ruby एक undefined constant की तरह treat करता है।
  3. जहाँ && / || मतलब हो वहाँ and / or इस्तेमाल करना, क्योंकि इनकी precedence कम है और result बदल सकता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.