123456789_123456789_123456789_123456789_123456789_

Class: TrueClass

Relationships & Source Files
Inherits: Object
Defined in: object.c,
object.c

Overview

The class of the singleton object true.

Several of its methods act as operators:

One other method:

Instance Method Summary

Instance Method Details

#&(object) ⇒ Boolean

Returns false if object is false or nil, true otherwise:

true & Object.new # => true true & false # => false true & nil # => false

[ GitHub ]

  
# File 'object.c', line 1556

static VALUE
true_and(VALUE obj, VALUE obj2)
{
    return RBOOL(RTEST(obj2));
}

#==(other) ⇒ Boolean

Alias for Module#==. Returns whether self and other are the same object:

object = Object.new
object == object     # => true
object == Object.new # => false

Here in class Object, #==, #equal?, and #eql? are the same method. A subclass may override #== to provide class-specific meaning.

Unlike #==, the #equal? method should never be overridden by subclasses as it is used to determine object identity (that is, a.equal?(b) if and only if a is the same object as b):

obj = "a"
other = obj.dup

obj == other      #=> true
obj.equal? other  #=> false
obj.equal? obj    #=> true

The #eql? method returns true if obj and other refer to the same hash key. This is used by ::Hash to test members for equality. For any pair of objects where #eql? returns true, the #hash value of both objects must be equal. So any subclass that overrides #eql? should also override #hash appropriately.

For objects of class ::Object, #eql? is synonymous with #==. Subclasses normally continue this tradition by aliasing #eql? to their overridden #== method, but there are exceptions. ::Numeric types, for example, perform type conversion across #==, but not across #eql?, so:

1 == 1.0     #=> true
1.eql? 1.0   #=> false

#===

[ GitHub ]

#^(object) ⇒ !object

Returns true if object is false or nil, false otherwise:

true ^ Object.new # => false
true ^ false      # => true
true ^ nil        # => true
[ GitHub ]

  
# File 'object.c', line 1600

static VALUE
true_xor(VALUE obj, VALUE obj2)
{
    return rb_obj_not(obj2);
}

#to_s ⇒ 'true' #inspect ⇒ 'true'

Alias for #to_s.

#to_s ⇒ 'true' Also known as: #inspect

Returns string 'true':

true.to_s # => "true"

#inspect is an alias for to_s.

[ GitHub ]

  
# File 'object.c', line 1537

VALUE
rb_true_to_s(VALUE obj)
{
    return rb_cTrueClass_to_s;
}

#|(object) ⇒ true

Returns true:

true | Object.new # => true
true | false      # => true
true | nil        # => true

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
[ GitHub ]

  
# File 'object.c', line 1581

static VALUE
true_or(VALUE obj, VALUE obj2)
{
    return Qtrue;
}