Class: NilClass

Inherits:
Object show all
Defined in:
object.c,
object.c

Overview

The class of the singleton object nil.

Instance Method Summary collapse

Instance Method Details

#&(obj) ⇒ false #&(obj) ⇒ false

And—Returns false. obj is always evaluated as it is the argument to a method call—there is no short-circuit evaluation in this case.

Overloads:

  • #&(obj) ⇒ false

    Returns:

    • (false)
  • #&(obj) ⇒ false

    Returns:

    • (false)


1314
1315
1316
1317
1318
# File 'object.c', line 1314

static VALUE
false_and(VALUE obj, VALUE obj2)
{
    return Qfalse;
}

#^(obj) ⇒ Boolean #^(obj) ⇒ Boolean

Exclusive Or—If obj is nil or false, returns false; otherwise, returns true.

Overloads:

  • #^(obj) ⇒ Boolean

    Returns:

    • (Boolean)
  • #^(obj) ⇒ Boolean

    Returns:

    • (Boolean)


1349
1350
1351
1352
1353
# File 'object.c', line 1349

static VALUE
false_xor(VALUE obj, VALUE obj2)
{
    return RTEST(obj2)?Qtrue:Qfalse;
}

#inspectObject

Always returns the string “nil”.



1198
1199
1200
1201
1202
# File 'object.c', line 1198

static VALUE
nil_inspect(VALUE obj)
{
    return rb_usascii_str_new2("nil");
}

#nil?true

Only the object nil responds true to nil?.

Returns:

  • (true)

Returns:

  • (Boolean)


1362
1363
1364
1365
1366
# File 'object.c', line 1362

static VALUE
rb_true(VALUE obj)
{
    return Qtrue;
}

#rationalize([eps]) ⇒ Object

Returns zero as a rational. The optional argument eps is always ignored.



1920
1921
1922
1923
1924
1925
# File 'rational.c', line 1920

static VALUE
nilclass_rationalize(int argc, VALUE *argv, VALUE self)
{
    rb_scan_args(argc, argv, "01", NULL);
    return nilclass_to_r(self);
}

#to_aObject

call-seq:

   nil.to_a    -> []

Always returns an empty array.

   nil.to_a   #=> []


1168
1169
1170
1171
1172
# File 'object.c', line 1168

static VALUE
nil_to_a(VALUE obj)
{
    return rb_ary_new2(0);
}

#to_cObject

Returns zero as a complex.



1470
1471
1472
1473
1474
# File 'complex.c', line 1470

static VALUE
nilclass_to_c(VALUE self)
{
    return rb_complex_new1(INT2FIX(0));
}

#to_f0.0

Always returns zero.

nil.to_f   #=> 0.0

Returns:

  • (0.0)


1138
1139
1140
1141
1142
# File 'object.c', line 1138

static VALUE
nil_to_f(VALUE obj)
{
    return DBL2NUM(0.0);
}

#to_hObject

call-seq:

   nil.to_h    -> {}

Always returns an empty hash.

   nil.to_h   #=> {}


1185
1186
1187
1188
1189
# File 'object.c', line 1185

static VALUE
nil_to_h(VALUE obj)
{
    return rb_hash_new();
}

#to_i0

Always returns zero.

nil.to_i   #=> 0

Returns:

  • (0)


1123
1124
1125
1126
1127
# File 'object.c', line 1123

static VALUE
nil_to_i(VALUE obj)
{
    return INT2FIX(0);
}

#to_rObject

Returns zero as a rational.



1907
1908
1909
1910
1911
# File 'rational.c', line 1907

static VALUE
nilclass_to_r(VALUE self)
{
    return rb_rational_new1(INT2FIX(0));
}

#to_sObject

Always returns the empty string.



1151
1152
1153
1154
1155
# File 'object.c', line 1151

static VALUE
nil_to_s(VALUE obj)
{
    return rb_usascii_str_new(0, 0);
}

#|(obj) ⇒ Boolean #|(obj) ⇒ Boolean

Or—Returns false if obj is nil or false; true otherwise.

Overloads:

  • #|(obj) ⇒ Boolean

    Returns:

    • (Boolean)
  • #|(obj) ⇒ Boolean

    Returns:

    • (Boolean)


1330
1331
1332
1333
1334
# File 'object.c', line 1330

static VALUE
false_or(VALUE obj, VALUE obj2)
{
    return RTEST(obj2)?Qtrue:Qfalse;
}