class Object

Parent:
BasicObject
Included modules:
Kernel

Object is the default root of all Ruby objects. Object inherits from BasicObject which allows creating alternate object hierarchies. Methods on Object are available to all classes unless explicitly overridden.

Object mixes in the Kernel module, making the built-in kernel functions globally accessible. Although the instance methods of Object are defined by the Kernel module, we have chosen to document them here for clarity.

When referencing constants in classes inheriting from Object you do not need to use the full namespace. For example, referencing File inside YourClass will find the top-level File class.

In the descriptions of Object’s methods, the parameter symbol refers to a symbol, which is either a quoted string or a Symbol (such as :name).

What’s Here

First, what’s elsewhere. Class Object:

Here, class Object provides methods for:

Querying

  • !~: Returns true if self does not match the given object, otherwise false.

  • <=>: Returns 0 if self and the given object object are the same object, or if self == object; otherwise returns nil.

  • ===: Implements case equality, effectively the same as calling ==.

  • eql?: Implements hash equality, effectively the same as calling ==.

  • kind_of? (aliased as is_a?): Returns whether given argument is an ancestor of the singleton class of self.

  • instance_of?: Returns whether self is an instance of the given class.

  • instance_variable_defined?: Returns whether the given instance variable is defined in self.

  • method: Returns the Method object for the given method in self.

  • methods: Returns an array of symbol names of public and protected methods in self.

  • nil?: Returns false. (Only nil responds true to method nil?.)

  • object_id: Returns an integer corresponding to self that is unique for the current process

  • private_methods: Returns an array of the symbol names of the private methods in self.

  • protected_methods: Returns an array of the symbol names of the protected methods in self.

  • public_method: Returns the Method object for the given public method in self.

  • public_methods: Returns an array of the symbol names of the public methods in self.

  • respond_to?: Returns whether self responds to the given method.

  • singleton_class: Returns the singleton class of self.

  • singleton_method: Returns the Method object for the given singleton method in self.

  • singleton_methods: Returns an array of the symbol names of the singleton methods in self.

  • define_singleton_method: Defines a singleton method in self for the given symbol method-name and block or proc.

  • extend: Includes the given modules in the singleton class of self.

  • public_send: Calls the given public method in self with the given argument.

  • send: Calls the given method in self with the given argument.

Instance Variables

Other

  • clone: Returns a shallow copy of self, including singleton class and frozen state.

  • define_singleton_method: Defines a singleton method in self for the given symbol method-name and block or proc.

  • display: Prints self to the given IO stream or $stdout.

  • dup: Returns a shallow unfrozen copy of self.

  • enum_for (aliased as to_enum): Returns an Enumerator for self using the using the given method, arguments, and block.

  • extend: Includes the given modules in the singleton class of self.

  • freeze: Prevents further modifications to self.

  • hash: Returns the integer hash value for self.

  • inspect: Returns a human-readable string representation of self.

  • itself: Returns self.

  • method_missing: Method called when an undefined method is called on self.

  • public_send: Calls the given public method in self with the given argument.

  • send: Calls the given method in self with the given argument.

  • to_s: Returns a string representation of self.

Ruby Core © 1993–2024 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.