The superclass of all classes. Defines the general behavior of objects.
Checks whether 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.
This method is mainly 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.
Returns the receiver class.
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 results in TypeError exceptions.
When other is self, returns true. This method must not be redefined.
Prohibits an object's contents from being modified. Modifying a frozen object throws a TypeError exception.
Returns true if the object's contents are prohibited from being modified.
Returns the object in a human-readable string format.
Returns true if 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.
Gets and returns the value of the object's instance variables.
Specify the instance variable name for var using a character string or a Symbol.
Returns nil if the instance variable is undefined.
class Foo def initialize @foo = 1 end end obj = Foo.new p obj.instance_variable_get("@foo") # => 1 p obj.instance_variable_get(:@foo) # => 1 p obj.instance_variable_get(:@bar) # => nil
Sets object's instance variable to value val and returns val.
Specify the instance variable name for var using a character string or a Symbol.
A new instance variable is defined if one has not already been.
obj = Object.new p obj.instance_variable_set("@foo", 1) # => 1 p obj.instance_variable_set(:@foo, 2) # => 2 p obj.instance_variable_get(:@foo) # => 2
Returns the object's instance variable name as a string array.
obj = Object.new obj.instance_eval { @foo, @bar = nil } p obj.instance_variables # => ["@foo", "@bar"]
Returns true if 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
Returns the Method object that encapsulated the name method of self in an object. name is specified with a Symbol or character string.
Returns true if the receiver is nil.
Returns true if the object has the public method name.
name is a Symbol or character string. Returns true even for the private method if priv is true.
Calls args to the argument, calls the object's name method, and returns the result of the method.
Passes the block as is when called with a block. The method name name is a character string or Symbol.
Returns a unique integer for each object. The integers are assigned to objects arbitrarily.
Called internally when an object's implicit conversion to an array is required.
Called internally when an object's implicit conversion to a hash is required.
Called internally when an object's implicit conversion to an integer is required.
Returns the string representation of the object.
When non-string objects are passed to arguments in print and sprintf, use this method to convert the objects to strings.
Called when an object's implicit conversion to a string is required.
The object 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, as 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.