class Object

include Kernel

The root of the class hierarchy: every value is an Object, and the methods here apply to all of them. It includes Kernel, whose private functions (puts, rand, exit) are called without a receiver.

<prelude>:26

Methods

def ==(other: Object) -> Bool

Whether the value equals other. Built-in values (numbers, strings, arrays, hashes, data values, enum variants) compare by contents; an instance of a class compares by identity unless the class defines ==.

[1, "a"] == [1, "a"]   # => true
Object.new == Object.new   # => false

<prelude>:37

def !=(other: Object) -> Bool

The negation of ==.

<prelude>:39

def equal?(other: Object) -> Bool

Whether the value is the same object as other: identity, whatever == says. Meaningful for instances of classes and builders: numbers, nil and symbols are the same object when they are equal, and equal immutable values (strings from the same literal) may be shared.

<prelude>:44

def hash -> Int

A hash code: values that are == have the same one. A class that defines == defines hash to agree with it.

<prelude>:47

def to_s -> String

The value as a string, for puts and interpolation. For an instance of a class, the class name in the form #<Point>; for an exception, its message; for a data value or an enum variant, the default inspect. It does not call an inspect the class defines.

<prelude>:52

def inspect -> String

A developer-readable representation, as p prints it: strings quoted, collections with their elements' inspect, an object with its fields (#<Point @x=1, @y=2>).

<prelude>:56

def nil? -> Bool

Whether the value is nil. Narrows the receiver's type in the branch where it is not.

<prelude>:59

def class -> Type[Object]

The class of the value, as a Type[Object] (Class) value.

1.class.name        # => "Int"
[1].class.name      # => "Array"
1.class <= Comparable    # => true

<prelude>:67

def is_a?(klass: Type[Object]) -> Bool

x.is_a?(klass) with a class value: whether x is an instance of it or of a subclass. (x.is_a?(Int), with a type, narrows x.)

<prelude>:70

def frozen? -> Bool

Whether the value cannot be changed: false only for the builders Array::Builder, Hash::Builder, Set::Builder, String::Builder and Bytes::Builder. true for every other value, instances of classes with var fields included.

<prelude>:75

def dup -> Self

A copy of the value. A builder or an instance of a class is copied (shallowly: the fields refer to the same values); an immutable built-in value (an array, a string, ...) is returned as it is.

<prelude>:79

def instance_exec[R](&: Self.() -> R) -> R

Run a block with a receiver (self.(...) -> R) with self = this object.

5.instance_exec { self + 1 }              # => 6
5.instance_exec(2) { |n| self * n }       # => 10

<prelude>:86

def instance_exec[A, R](a: A, &: Self.(A) -> R) -> R

Run a block with a receiver (self.(...) -> R) with self = this object.

5.instance_exec { self + 1 }              # => 6
5.instance_exec(2) { |n| self * n }       # => 10

<prelude>:88

def instance_exec[A, B, R](a: A, b: B, &: Self.(A, B) -> R) -> R

Run a block with a receiver (self.(...) -> R) with self = this object.

5.instance_exec { self + 1 }              # => 6
5.instance_exec(2) { |n| self * n }       # => 10

<prelude>:90

def tap(&: (Self) -> Void) -> Self

Yields the receiver to the block and returns the receiver, to look at a value in the middle of a chain.

<prelude>:94

def then[U](&: (Self) -> U) -> U

The block's result for the receiver.

"hello".then { |s| s.size }   # => 5

<prelude>:104