Boolean Values क्या हैं
Boolean values true और false हैं, एक light switch की तरह जो on या off है। Ruby इन्हें yes-or-no questions answer करने के लिए इस्तेमाल करता है।
In this page:
Syntax
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
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
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. #}
आम गलतियां
- यह उम्मीद करना कि
0या एक empty string false होगी, जब Ruby में सिर्फfalseऔरnilfalsy हैं। TrueयाTRUEलिखना, जिसे Ruby एक undefined constant की तरह treat करता है।- जहाँ
&&/||मतलब हो वहाँand/orइस्तेमाल करना, क्योंकि इनकी precedence कम है और result बदल सकता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: