55part of dart.core;
66
77/**
8- * The reserved words [: true:] and [: false:] denote objects that are the only
8+ * The reserved words ` true` and ` false` denote objects that are the only two
99 * instances of this class.
1010 *
1111 * It is a compile-time error for a class to attempt to extend or implement
@@ -23,21 +23,22 @@ class bool {
2323 * the result is the [defaultValue] .
2424 *
2525 * The result is the same as would be returned by:
26- *
27- * (const String.fromEnvironment(name) == "true")
28- * ? true
29- * : (const String.fromEnvironment(name) == "false")
30- * ? false
31- * : defaultValue
32- *
26+ * ```dart
27+ * (const String.fromEnvironment(name) == "true")
28+ * ? true
29+ * : (const String.fromEnvironment(name) == "false")
30+ * ? false
31+ * : defaultValue
32+ * ```
3333 * Example:
34- *
35- * const loggingFlag = const bool.fromEnvironment("logging");
36- *
34+ * ```dart
35+ * const loggingFlag = const bool.fromEnvironment("logging");
36+ * ```
3737 * If you want to use a different truth-string than `"true"` , you can use the
3838 * [String.fromEnvironment] constructor directly:
39- *
40- * const isLoggingOn = (const String.fromEnvironment("logging") == "on");
39+ * ```dart
40+ * const isLoggingOn = (const String.fromEnvironment("logging") == "on");
41+ * ```
4142 */
4243 // The .fromEnvironment() constructors are special in that we do not want
4344 // users to call them using "new". We prohibit that by giving them bodies
@@ -50,9 +51,24 @@ class bool {
5051
5152 external int get hashCode;
5253
54+ /// The logical conjuncton ("and") of this and [other] .
55+ ///
56+ /// Returns `true` if both this and [other] are `true` , and `false` otherwise.
57+ //TODO(lrn): Remove "as bool" in Dart 2.
58+ bool operator & (bool other) => (other as bool ) && this ;
59+
60+ /// The logical disjunction ("inclusive or") of this and [other] .
61+ ///
62+ /// Returns `true` if either this or [other] is `true` , and `false` otherwise.
63+ bool operator | (bool other) => (other as bool ) || this ;
64+
65+ /// The logical exclusive disjuction ("exclusive or") of this and [other] .
66+ ///
67+ /// Returns whether this and [other] are neither both `true` nor both `false` .
68+ bool operator ^ (bool other) => ! (other as bool ) == this ;
69+
5370 /**
54- * Returns [:"true":] if the receiver is [:true:] , or [:"false":] if the
55- * receiver is [:false:] .
71+ * Returns either `"true"` for `true` and `"false"` for `false` .
5672 */
5773 String toString () {
5874 return this ? "true" : "false" ;
0 commit comments