From 671ddb1eee1334e3b5cc209ec4c981ae2d0ba9dc Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Thu, 16 Mar 2023 08:59:41 -0500 Subject: [DOC] Enhanced RDoc for TrueClass (#7521) --- object.c | 70 ++++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index 0256297b10..983fde9b09 100644 --- a/object.c +++ b/object.c @@ -108,6 +108,8 @@ rb_obj_setup(VALUE obj, VALUE klass, VALUE type) /* * call-seq: + * true === other -> true or false + * false === other -> true or false * nil === other -> true or false * * Returns +true+ or +false+. @@ -1373,21 +1375,35 @@ nil_match(VALUE obj1, VALUE obj2) return Qnil; } -/*********************************************************************** +/* * Document-class: TrueClass * - * The global value true is the only instance of class - * TrueClass and represents a logically true value in - * boolean expressions. The class provides operators allowing - * true to be used in logical expressions. + * The class of the singleton object +true+. + * + * Several of its methods act as operators: + * + * - #& + * - #| + * - #=== + * - #^ + * + * One other method: + * + * - #to_s and its alias #inspect. + * */ /* * call-seq: - * true.to_s -> "true" + * true.to_s -> 'true' + * + * Returns string 'true': + * + * true.to_s # => "true" + * + * TrueClass#inspect is an alias for TrueClass#to_s. * - * The string representation of true is "true". */ VALUE @@ -1399,10 +1415,14 @@ rb_true_to_s(VALUE obj) /* * call-seq: - * true & obj -> true or false + * true & object -> true or false + * + * Returns +false+ if +object+ is +false+ or +nil+, +true+ otherwise: + * + * true & Object.new # => true + * true & false # => false + * true & nil # => false * - * And---Returns false if obj is - * nil or false, true otherwise. */ static VALUE @@ -1413,18 +1433,21 @@ true_and(VALUE obj, VALUE obj2) /* * call-seq: - * true | obj -> true + * true | object -> true * - * Or---Returns true. As obj is an argument to - * a method call, it is always evaluated; there is no short-circuit - * evaluation in this case. + * Returns +true+: * - * true | puts("or") - * true || puts("logical or") + * true | Object.new # => true + * true | false # => true + * true | nil # => true * - * produces: + * Argument +object+ is evaluated. + * This is different from +true+ with the short-circuit operator, + * whose operand is evaluated only if necessary: + * + * true | raise # => Raises RuntimeError. + * true || raise # => true * - * or */ static VALUE @@ -1436,11 +1459,14 @@ true_or(VALUE obj, VALUE obj2) /* * call-seq: - * true ^ obj -> !obj + * true ^ object -> !object + * + * Returns +true+ if +object+ is +false+ or +nil+, +false+ otherwise: + * + * true ^ Object.new # => false + * true ^ false # => true + * true ^ nil # => true * - * Exclusive Or---Returns true if obj is - * nil or false, false - * otherwise. */ static VALUE -- cgit v1.2.1