mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-10 00:36:48 +02:00
Ruby: nil != false
Instead of saying `nil == false` (which is incorrect), show that negating `nil` and `false` produces `true`. Negating anything else will produce `false`.
This commit is contained in:
@@ -43,17 +43,18 @@ false.class #=> FalseClass
|
|||||||
1 == 1 #=> true
|
1 == 1 #=> true
|
||||||
2 == 1 #=> false
|
2 == 1 #=> false
|
||||||
|
|
||||||
# apart from false itself, nil is the only other 'falsey' value
|
|
||||||
|
|
||||||
nil == false #=> true
|
|
||||||
0 == false #=> false
|
|
||||||
|
|
||||||
# Inequality
|
# Inequality
|
||||||
1 != 1 #=> false
|
1 != 1 #=> false
|
||||||
2 != 1 #=> true
|
2 != 1 #=> true
|
||||||
!true #=> false
|
!true #=> false
|
||||||
!false #=> true
|
!false #=> true
|
||||||
|
|
||||||
|
# apart from false itself, nil is the only other 'falsey' value
|
||||||
|
|
||||||
|
!nil #=> true
|
||||||
|
!false #=> true
|
||||||
|
!0 #=> false
|
||||||
|
|
||||||
# More comparisons
|
# More comparisons
|
||||||
1 < 10 #=> true
|
1 < 10 #=> true
|
||||||
1 > 10 #=> false
|
1 > 10 #=> false
|
||||||
|
Reference in New Issue
Block a user