Ruby Object Functions

EditRocket provides the following information on Object functions in the Ruby source code builder.

class - Returns the class of obj, now preferred over Object#type, as an object's type in Ruby is only loosely tied to that object's class. This method must always be called with an explicit receiver, as class is also a reserved word in Ruby.

clone - Produces a shallow copy of obj---the instance variables of obj are copied, but not the objects they reference. Copies the frozen and tainted state of obj. See also the discussion under Object#dup.

dclone() -

display(port=$>) - "Prints obj on the given port (default $>). Equivalent to:"

dup - Produces a shallow copy of obj---the instance variables of obj are copied, but not the objects they reference. dup copies the tainted state of obj. See also the discussion under Object#clone. In general, clone and dup may have different semantics in descendent classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendent object to create the new instance.

enum_for(method = :each, *args) - Returns Enumerable::Enumerator.new(self, method, *args).

eql?(other) - Equality---At the Object level, == returns true only if obj and other are the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning.

equal?(other) - Equality---At the Object level, == returns true only if obj and other are the same object. Typically, this method is overridden in descendent classes to provide class-specific meaning.

extend(module, ...) - Adds to obj the instance methods from each module given as a parameter.

freeze - Prevents further modifications to obj. A TypeError will be raised if modification is attempted. There is no way to unfreeze a frozen object. See also Object#frozen?.

frozen? - Returns the freeze status of obj.

hash - Generates a Fixnum hash value for this object. This function must have the property that a.eql?(b) implies a.hash == b.hash. The hash value is used by class Hash. Any hash value that exceeds the capacity of a Fixnum will be truncated before being used.

id - Soon-to-be deprecated version of Object#object_id.

inspect - Returns a string containing a human-readable representation of obj. If not overridden, uses the to_s method to generate the string.

instance_eval(string [, filename [, lineno]] ) - Evaluates a string containing Ruby source code, or the given block, within the context of the receiver (obj). In order to set the context, the variable self is set to obj while the code is executing, giving the code access to obj's instance variables. In the version of instance_eval that takes a String, the optional second and third parameters supply a filename and starting line number that are used when reporting compilation errors.

instance_of?(class) - Returns true if obj is an instance of the given class. See also Object#kind_of?.

instance_variable_defined?(symbol) - Returns true if the given instance variable is defined in obj.

instance_variable_get(symbol) - Returns the value of the given instance variable, or nil if the instance variable is not set. The @ part of the variable name should be included for regular instance variables. Throws a NameError exception if the supplied symbol is not valid as an instance variable name.

instance_variable_set(symbol, obj) - Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation. The variable did not have to exist prior to this call.

instance_variables - Returns an array of instance variable names for the receiver. Note that simply defining an accessor does not create the corresponding instance variable.

is_a?(class) - Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.

kind_of?(class) - Returns true if class is the class of obj, or if class is one of the superclasses of obj or modules included in obj.

method(sym) - Looks up the named method as a receiver in obj, returning a Method object (or raising NameError). The Method object acts as a closure in obj's object instance, so instance variables and the value of self remain available.

methods - Returns a list of the names of methods publicly accessible in obj. This will include all the methods accessible in obj's ancestors.

new() - Not documented

nil?() - "call_seq:"

object_id - Returns an integer identifier for obj. The same number will be returned on all calls to id for a given object, and no two active objects will share an id. Object#object_id is a different concept from the :name notation, which returns the symbol id of name. Replaces the deprecated Object#id.

private_methods(all=true) - Returns the list of private methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.

protected_methods(all=true) - Returns the list of protected methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.

public_methods(all=true) - Returns the list of public methods accessible to obj. If the all parameter is set to false, only those methods in the receiver will be listed.

remove_instance_variable(symbol) - Removes the named instance variable from obj, returning that variable's value.

respond_to?(symbol, include_private=false) - Returns true> if obj responds to the given method. Private methods are included in the search only if the optional second parameter evaluates to true.

send(symbol [, args...]) - Invokes the method identified by symbol, passing it any arguments specified. You can use __send__ if the name send clashes with an existing method in obj.

singleton_method_added singleton_method_added(symbol) - Invoked as a callback whenever a singleton method is added to the receiver.

singleton_method_removed singleton_method_removed(symbol) - Invoked as a callback whenever a singleton method is removed from the receiver.

singleton_method_undefined singleton_method_undefined(symbol) - Invoked as a callback whenever a singleton method is undefined in the receiver.

singleton_methods(all=true) - Returns an array of the names of singleton methods for obj. If the optional all parameter is true, the list will include methods in modules included in obj.

taint - Marks obj as tainted---if the $SAFE level is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.

tainted? - Returns true if the object is tainted.

to_a - Returns an array representation of obj. For objects of class Object and others that don't explicitly override the method, the return value is an array containing self. However, this latter behavior will soon be obsolete.

to_enum(method = :each, *args) - Returns Enumerable::Enumerator.new(self, method, *args).

to_s - Returns a string representing obj. The default to_s prints the object's class and an encoding of the object id. As a special case, the top-level object that is the initial execution context of Ruby programs returns ``main.''

to_yaml( opts = {} ) -

to_yaml_properties() -

to_yaml_style() -

type - Deprecated synonym for Object#class.

untaint - Removes the taint from obj.