Object

The superclass of all classes. Defines the general behavior of objects.

Included Modules

Methods

self == other

Checks if self and other are equal. By default, has the same effect as equal?.

This method must be redefined with respect to each class's properties.

self === other

This method is mostly used for comparison within case statements. By default, acts like Object#==, but this behavior can be redefined in the subclass to implement an ownership check.

class

Returns the receiver class.

clone
dup

Creates a copy of the object. clone returns a complete clone of the original object, including freeze status and singleton methods, while dup duplicates the object contents only.

Note that clone and dup perform only a shallow copy. They duplicate the object itself, but nothing it points to (such as array elements).

For duplicated objects,

obj.equal?(obj.clone)

generally does not hold, while

obj == obj.clone

is correct in most cases.

Attempting to duplicate true, false, nil, Numeric objects, Symbol objects, and the like result in TypeError exceptions.

equal?(other)

When other is self, returns true. This method must not be redefined.

freeze

Prohibits an object's contents from being modified. Modifying a frozen object throws a TypeError exception.

frozen?

Returns true when the object's contents are prohibited from being modified.

inspect

Returns the object in a human-readable string format.

instance_of?(klass)

Returns true when self is a direct instance of the class klass. When obj.instance_of?(c) is true, obj.kind_of?(c) is always true as well.

is_a?(mod)
kind_of?(mod)

Returns true when self is the class mod (or its subclass). or a class (or its subclass) that includes the module mod.

module M
end
class C < Object
  include M
end
class S < C
end

obj = S.new
p obj.is_a? S       # true
p obj.is_a? M       # true
p obj.is_a? C       # true
p obj.is_a? Object  # true
p obj.is_a? Hash    # false
nil?

Checks if the receiver is nil.

object_id

Returns a unique integer for each object. The integers are assigned to objects arbitrarily.

to_ary

Called internally when an object's implicit conversion to an array is required.

to_hash

Called internally when an object's implicit conversion to a hash is required.

to_int

Called internally when an object's implicit conversion to an integer is required.

to_s

Returns the string representation of the object. This method is used internally by print and sprintf.

When non-string objects are passed to arguments in print and sprintf, use this method to convert the objects to strings.

to_str

Called when an object's implicit conversion to a string is required.

Private Method

initialize

The initialization method for user-defined classes. This method is called from Class#new to initialize a newly created object. The default behavior is to do nothing; it is assumed that this method will be redefined in the subclass as needed. The argument given to Class#new will be passed to initialize as is.

Converted from CHM to HTML with chm2web Pro 2.85 (unicode)