Ruby  3.4.0dev (2024-11-22 revision 37a72b0150ec36b4ea27175039afc28c62207b0c)
Data Structures | Macros | Functions | Variables
Core objects and their operations

Macros

#define RUBY_INTEGER_UNIFICATION   1
 
#define case_equal   rb_equal
 
#define rb_obj_class_inherited   rb_obj_dummy1
 
#define rb_obj_mod_method_added   rb_obj_dummy1
 
#define rb_obj_mod_method_removed   rb_obj_dummy1
 
#define rb_obj_mod_method_undefined   rb_obj_dummy1
 
#define rb_obj_singleton_method_added   rb_obj_dummy1
 
#define rb_obj_singleton_method_removed   rb_obj_dummy1
 
#define rb_obj_singleton_method_undefined   rb_obj_dummy1
 
#define rb_obj_mod_const_added   rb_obj_dummy1
 
#define rb_obj_mod_extended   rb_obj_dummy1
 
#define rb_obj_mod_included   rb_obj_dummy1
 
#define rb_obj_mod_prepended   rb_obj_dummy1
 
#define rb_obj_initialize   rb_obj_dummy0
 
#define false_or   true_and
 
#define false_xor   true_and
 
#define wrong_constant_name   bad_const_name
 
#define id_for_var(obj, name, type)   id_for_setter(obj, name, type, bad_##type##_name)
 
#define id_for_setter(obj, name, type, message)    check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))
 
#define IMPLICIT_CONVERSIONS   7
 
#define try_to_int(val, mid, raise)    convert_type_with_id(val, "Integer", mid, raise, -1)
 
#define rb_to_integer(val, method, mid)    rb_to_integer_with_id_exception(val, method, mid, TRUE)
 

Functions

static VALUE rb_class_of (VALUE obj)
 Object to class mapping function. More...
 
size_t rb_obj_embedded_size (uint32_t numiv)
 Internal header for Object. More...
 
VALUE rb_obj_hide (VALUE obj)
 Make the object invisible from Ruby code. More...
 
VALUE rb_obj_reveal (VALUE obj, VALUE klass)
 Make a hidden object visible again. More...
 
VALUE rb_class_allocate_instance (VALUE klass)
 
VALUE rb_obj_setup (VALUE obj, VALUE klass, VALUE type)
 Fills common fields in the object. More...
 
VALUE rb_equal (VALUE obj1, VALUE obj2)
 This function is an optimised version of calling #==. More...
 
int rb_eql (VALUE obj1, VALUE obj2)
 Checks for equality of the passed objects, in terms of Object#eql?. More...
 
VALUE rb_obj_hash (VALUE obj)
 
VALUE rb_class_real (VALUE cl)
 Finds a "real" class. More...
 
VALUE rb_obj_class (VALUE obj)
 Queries the class of an object. More...
 
static VALUE rb_obj_singleton_class (VALUE obj)
 
static void init_copy (VALUE dest, VALUE obj)
 
static VALUE immutable_obj_clone (VALUE obj, VALUE kwfreeze)
 
static VALUE mutable_obj_clone (VALUE obj, VALUE kwfreeze)
 
static VALUE obj_freeze_opt (VALUE freeze)
 
static VALUE rb_obj_clone2 (rb_execution_context_t *ec, VALUE obj, VALUE freeze)
 
VALUE rb_get_freeze_opt (int argc, VALUE *argv)
 
VALUE rb_obj_clone_setup (VALUE obj, VALUE clone, VALUE kwfreeze)
 
VALUE rb_obj_clone (VALUE obj)
 Produces a shallow copy of the given object. More...
 
VALUE rb_obj_dup_setup (VALUE obj, VALUE dup)
 
VALUE rb_obj_dup (VALUE obj)
 Duplicates the given object. More...
 
static VALUE rb_obj_itself (VALUE obj)
 
VALUE rb_obj_size (VALUE self, VALUE args, VALUE obj)
 
VALUE rb_obj_init_copy (VALUE obj, VALUE orig)
 Default implementation of #initialize_copy More...
 
VALUE rb_obj_init_dup_clone (VALUE obj, VALUE orig)
 Default implementation of #initialize_dup More...
 
static VALUE rb_obj_init_clone (int argc, VALUE *argv, VALUE obj)
 Default implementation of #initialize_clone More...
 
VALUE rb_any_to_s (VALUE obj)
 Generates a textual representation of the given object. More...
 
VALUE rb_inspect (VALUE obj)
 Generates a human-readable textual representation of the given object. More...
 
static int inspect_i (ID id, VALUE value, st_data_t a)
 
static VALUE inspect_obj (VALUE obj, VALUE str, int recur)
 
static VALUE rb_obj_inspect (VALUE obj)
 
static VALUE class_or_module_required (VALUE c)
 
static VALUE class_search_ancestor (VALUE cl, VALUE c)
 
VALUE rb_obj_is_instance_of (VALUE obj, VALUE c)
 Queries if the given object is a direct instance of the given class. More...
 
static VALUE class_search_class_ancestor (VALUE cl, VALUE c)
 
VALUE rb_obj_is_kind_of (VALUE obj, VALUE c)
 Queries if the given object is an instance (of possibly descendants) of the given class. More...
 
static VALUE rb_obj_dummy (void)
 
static VALUE rb_obj_dummy0 (VALUE _)
 
static VALUE rb_obj_dummy1 (VALUE _x, VALUE _y)
 
VALUE rb_obj_freeze (VALUE obj)
 Just calls rb_obj_freeze_inline() inside. More...
 
VALUE rb_obj_frozen_p (VALUE obj)
 Just calls RB_OBJ_FROZEN() inside. More...
 
VALUE rb_nil_to_s (VALUE obj)
 
static VALUE nil_to_a (VALUE obj)
 
static VALUE nil_to_h (VALUE obj)
 
static VALUE nil_inspect (VALUE obj)
 
static VALUE nil_match (VALUE obj1, VALUE obj2)
 
VALUE rb_true_to_s (VALUE obj)
 
static VALUE true_and (VALUE obj, VALUE obj2)
 
static VALUE true_or (VALUE obj, VALUE obj2)
 
static VALUE true_xor (VALUE obj, VALUE obj2)
 
VALUE rb_false_to_s (VALUE obj)
 
static VALUE false_and (VALUE obj, VALUE obj2)
 
static VALUE rb_true (VALUE obj)
 
VALUE rb_false (VALUE obj)
 
static VALUE rb_obj_not_match (VALUE obj1, VALUE obj2)
 
static VALUE rb_obj_cmp (VALUE obj1, VALUE obj2)
 
VALUE rb_mod_to_s (VALUE klass)
 
static VALUE rb_mod_freeze (VALUE mod)
 
static VALUE rb_mod_eqq (VALUE mod, VALUE arg)
 
VALUE rb_class_inherited_p (VALUE mod, VALUE arg)
 Determines if the given two modules are relatives. More...
 
static VALUE rb_mod_lt (VALUE mod, VALUE arg)
 
static VALUE rb_mod_ge (VALUE mod, VALUE arg)
 
static VALUE rb_mod_gt (VALUE mod, VALUE arg)
 
static VALUE rb_mod_cmp (VALUE mod, VALUE arg)
 
static VALUE rb_mod_initialize_exec (VALUE module)
 
static VALUE rb_mod_initialize (VALUE module)
 
static VALUE rb_mod_initialize_clone (int argc, VALUE *argv, VALUE clone)
 
static VALUE rb_class_initialize (int argc, VALUE *argv, VALUE klass)
 
static rb_alloc_func_t class_get_alloc_func (VALUE klass)
 
static VALUE class_call_alloc_func (rb_alloc_func_t allocator, VALUE klass)
 
static VALUE rb_class_alloc_m (VALUE klass)
 
static VALUE rb_class_alloc (VALUE klass)
 
VALUE rb_obj_alloc (VALUE klass)
 Allocates an instance of the given class. More...
 
VALUE rb_class_new_instance_pass_kw (int argc, const VALUE *argv, VALUE klass)
 Identical to rb_class_new_instance(), except it passes the passed keywords if any to the #initialize method. More...
 
VALUE rb_class_new_instance_kw (int argc, const VALUE *argv, VALUE klass, int kw_splat)
 Identical to rb_class_new_instance(), except you can specify how to handle the last element of the given array. More...
 
VALUE rb_class_new_instance (int argc, const VALUE *argv, VALUE klass)
 Allocates, then initialises an instance of the given class. More...
 
VALUE rb_class_superclass (VALUE klass)
 Returns the superclass of klass. More...
 
VALUE rb_class_get_superclass (VALUE klass)
 Returns the superclass of a class. More...
 
static ID check_setter_id (VALUE obj, VALUE *pname, int(*valid_id_p)(ID), int(*valid_name_p)(VALUE), const char *message, size_t message_len)
 
static int rb_is_attr_name (VALUE name)
 
static int rb_is_attr_id (ID id)
 
static ID id_for_attr (VALUE obj, VALUE name)
 
static VALUE rb_mod_attr_reader (int argc, VALUE *argv, VALUE klass)
 
static VALUE rb_mod_attr_writer (int argc, VALUE *argv, VALUE klass)
 
static VALUE rb_mod_attr_accessor (int argc, VALUE *argv, VALUE klass)
 
static VALUE rb_mod_const_get (int argc, VALUE *argv, VALUE mod)
 
static VALUE rb_mod_const_set (VALUE mod, VALUE name, VALUE value)
 
static VALUE rb_mod_const_defined (int argc, VALUE *argv, VALUE mod)
 
static VALUE rb_mod_const_source_location (int argc, VALUE *argv, VALUE mod)
 
static VALUE rb_obj_ivar_get (VALUE obj, VALUE iv)
 
static VALUE rb_obj_ivar_set_m (VALUE obj, VALUE iv, VALUE val)
 
static VALUE rb_obj_ivar_defined (VALUE obj, VALUE iv)
 
static VALUE rb_mod_cvar_get (VALUE obj, VALUE iv)
 
static VALUE rb_mod_cvar_set (VALUE obj, VALUE iv, VALUE val)
 
static VALUE rb_mod_cvar_defined (VALUE obj, VALUE iv)
 
static VALUE rb_mod_singleton_p (VALUE klass)
 
static int conv_method_index (const char *method)
 
static VALUE convert_type_with_id (VALUE val, const char *tname, ID method, int raise, int index)
 
static VALUE convert_type (VALUE val, const char *tname, const char *method, int raise)
 
VALUE rb_convert_type (VALUE val, int type, const char *tname, const char *method)
 Converts an object into another type. More...
 
VALUE rb_check_convert_type (VALUE val, int type, const char *tname, const char *method)
 Identical to rb_convert_type(), except it returns RUBY_Qnil instead of raising exceptions, in case of conversion failure. More...
 
static VALUE rb_to_integer_with_id_exception (VALUE val, const char *method, ID mid, int raise)
 
VALUE rb_check_to_integer (VALUE val, const char *method)
 Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger. More...
 
VALUE rb_to_int (VALUE val)
 Identical to rb_check_to_int(), except it raises in case of conversion mismatch. More...
 
VALUE rb_check_to_int (VALUE val)
 Identical to rb_check_to_integer(), except it uses #to_int for conversion. More...
 
static VALUE rb_check_to_i (VALUE val)
 
static VALUE rb_convert_to_integer (VALUE val, int base, int raise_exception)
 
VALUE rb_Integer (VALUE val)
 This is the logic behind Kernel#Integer. More...
 
VALUE rb_check_integer_type (VALUE val)
 
int rb_bool_expected (VALUE obj, const char *flagname, int raise)
 
int rb_opts_exception_p (VALUE opts, int default_value)
 
static VALUE rb_f_integer1 (rb_execution_context_t *ec, VALUE obj, VALUE arg)
 
static VALUE rb_f_integer (rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE base, VALUE exception)
 
static double rb_cstr_to_dbl_raise (const char *p, rb_encoding *enc, int badcheck, int raise, int *error)
 
double rb_cstr_to_dbl (const char *p, int badcheck)
 Converts a textual representation of a real number into a numeric, which is the nearest value that the return type can represent, of the value that the argument represents. More...
 
static double rb_str_to_dbl_raise (VALUE str, int badcheck, int raise, int *error)
 
 FUNC_MINIMIZED (double rb_str_to_dbl(VALUE str, int badcheck))
 
double rb_str_to_dbl (VALUE str, int badcheck)
 Identical to rb_cstr_to_dbl(), except it accepts a Ruby's string instead of C's. More...
 
static void conversion_to_float (VALUE val)
 
static void implicit_conversion_to_float (VALUE val)
 
static int to_float (VALUE *valp, int raise_exception)
 
static VALUE convert_type_to_float_protected (VALUE val)
 
static VALUE rb_convert_to_float (VALUE val, int raise_exception)
 
 FUNC_MINIMIZED (VALUE rb_Float(VALUE val))
 
VALUE rb_Float (VALUE val)
 This is the logic behind Kernel#Float. More...
 
static VALUE rb_f_float1 (rb_execution_context_t *ec, VALUE obj, VALUE arg)
 
static VALUE rb_f_float (rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts)
 
static VALUE numeric_to_float (VALUE val)
 
VALUE rb_to_float (VALUE val)
 Identical to rb_check_to_float(), except it raises on error. More...
 
VALUE rb_check_to_float (VALUE val)
 This is complicated. More...
 
static int basic_to_f_p (VALUE klass)
 
double rb_num2dbl (VALUE val)
 Converts an instance of rb_cNumeric into C's double. More...
 
VALUE rb_String (VALUE val)
 This is the logic behind Kernel#String. More...
 
static VALUE rb_f_string (VALUE obj, VALUE arg)
 
VALUE rb_Array (VALUE val)
 This is the logic behind Kernel#Array. More...
 
static VALUE rb_f_array (VALUE obj, VALUE arg)
 
VALUE rb_Hash (VALUE val)
 Equivalent to Kernel#Hash in Ruby. More...
 
static VALUE rb_f_hash (VALUE obj, VALUE arg)
 
static int dig_basic_p (VALUE obj, struct dig_method *cache)
 
static void no_dig_method (int found, VALUE recv, ID mid, int argc, const VALUE *argv, VALUE data)
 
static VALUE f_sprintf (int c, const VALUE *v, VALUE _)
 
static VALUE rb_f_loop_size (VALUE self, VALUE args, VALUE eobj)
 
void InitVM_Object (void)
 
void Init_Object (void)
 

Variables

VALUE rb_cEncoding
 Encoding class. More...
 
VALUE rb_mKernel
 Kernel module. More...
 
VALUE rb_mComparable
 Comparable module. More...
 
VALUE rb_mEnumerable
 Enumerable module. More...
 
VALUE rb_mErrno
 Errno module. More...
 
VALUE rb_mFileTest
 FileTest module. More...
 
VALUE rb_mGC
 GC module. More...
 
VALUE rb_mMath
 Math module. More...
 
VALUE rb_mProcess
 Process module. More...
 
VALUE rb_mWaitReadable
 IO::WaitReadable module. More...
 
VALUE rb_mWaitWritable
 IO::WaitReadable module. More...
 
VALUE rb_cBasicObject
 BasicObject class. More...
 
VALUE rb_cObject
 Object class. More...
 
VALUE rb_cArray
 Array class. More...
 
VALUE rb_cBinding
 Binding class. More...
 
VALUE rb_cClass
 Class class. More...
 
VALUE rb_cDir
 Dir class. More...
 
VALUE rb_cEncoding
 Encoding class. More...
 
VALUE rb_cEnumerator
 Enumerator class. More...
 
VALUE rb_cFalseClass
 FalseClass class. More...
 
VALUE rb_cFile
 File class. More...
 
VALUE rb_cComplex
 Complex class. More...
 
VALUE rb_cFloat
 Float class. More...
 
VALUE rb_cHash
 Hash class. More...
 
VALUE rb_cIO
 IO class. More...
 
VALUE rb_cInteger
 Module class. More...
 
VALUE rb_cMatch
 MatchData class. More...
 
VALUE rb_cMethod
 Method class. More...
 
VALUE rb_cModule
 Module class. More...
 
VALUE rb_cRefinement
 Refinement class. More...
 
VALUE rb_cNameErrorMesg
 NameError::Message class. More...
 
VALUE rb_cNilClass
 NilClass class. More...
 
VALUE rb_cNumeric
 Numeric class. More...
 
VALUE rb_cProc
 Proc class. More...
 
VALUE rb_cRandom
 Random class. More...
 
VALUE rb_cRange
 Range class. More...
 
VALUE rb_cRational
 Rational class. More...
 
VALUE rb_cRegexp
 Regexp class. More...
 
VALUE rb_cStat
 File::Stat class. More...
 
VALUE rb_cString
 String class. More...
 
VALUE rb_cStruct
 Struct class. More...
 
VALUE rb_cSymbol
 Symbol class. More...
 
VALUE rb_cThread
 Thread class. More...
 
VALUE rb_cTime
 Time class. More...
 
VALUE rb_cTrueClass
 TrueClass class. More...
 
VALUE rb_cUnboundMethod
 UnboundMethod class. More...
 
VALUE rb_stdin
 STDIN constant. More...
 
VALUE rb_stdout
 STDOUT constant. More...
 
VALUE rb_stderr
 STDERR constant. More...
 
VALUE rb_cRactor
 Ractor class. More...
 
VALUE rb_cBasicObject
 BasicObject class. More...
 
VALUE rb_mKernel
 Kernel module. More...
 
VALUE rb_cObject
 Documented in include/ruby/internal/globals.h. More...
 
VALUE rb_cModule
 Module class. More...
 
VALUE rb_cClass
 Class class. More...
 
VALUE rb_cRefinement
 Refinement class. More...
 
VALUE rb_cNilClass
 NilClass class. More...
 
VALUE rb_cTrueClass
 TrueClass class. More...
 
VALUE rb_cFalseClass
 FalseClass class. More...
 
static VALUE rb_cNilClass_to_s
 
static VALUE rb_cTrueClass_to_s
 
static VALUE rb_cFalseClass_to_s
 
static const char bad_instance_name [] = "'%1$s' is not allowed as an instance variable name"
 
static const char bad_class_name [] = "'%1$s' is not allowed as a class variable name"
 
static const char bad_const_name [] = "wrong constant name %1$s"
 
static const char bad_attr_name [] = "invalid attribute name '%1$s'"
 
static ID id_dig
 

Detailed Description

Macro Definition Documentation

◆ RUBY_INTEGER_UNIFICATION

#define RUBY_INTEGER_UNIFICATION   1
Deprecated:
This macro once was a thing in the old days, but makes no sense any longer today.

Exists here for backwards compatibility only. You can safely forget about it.

Definition at line 54 of file globals.h.

Function Documentation

◆ rb_any_to_s()

VALUE rb_any_to_s ( VALUE  obj)

Generates a textual representation of the given object.

Parameters
[in]objArbitrary ruby object.
Returns
An instance of rb_cString that represents obj.
Note
This is the default implementation of Object#to_s that each subclasses want to override.

Definition at line 669 of file object.c.

◆ rb_Array()

VALUE rb_Array ( VALUE  val)

This is the logic behind Kernel#Array.

Arguments are converted by first trying #to_ary, then #to_a, and if both failed, returns an array of length 1 that contains the passed argument as the sole contents.

Parameters
[in]valAn object to convert.
Returns
An instance of rb_cArray.

Definition at line 3750 of file object.c.

◆ rb_check_convert_type()

VALUE rb_check_convert_type ( VALUE  val,
int  type,
const char *  name,
const char *  mid 
)

Identical to rb_convert_type(), except it returns RUBY_Qnil instead of raising exceptions, in case of conversion failure.

It still raises exceptions for various reasons, like when the conversion method itself raises, though.

Parameters
[in]valAn object to convert.
[in]typeA value of enum ruby_value_type.
[in]nameName to display on error (e.g. "Array").
[in]midConversion method (e.g. "to_ary").
Exceptions
rb_eTypeErrorThe mid does not generate type.
Return values
RUBY_QnilNo conversion defined.
otherwiseAn object of the specified type.

Definition at line 3115 of file object.c.

◆ rb_check_to_float()

VALUE rb_check_to_float ( VALUE  val)

This is complicated.

  • When the passed object is already an instance of rb_cFloat, just returns it as-is.
  • When the passed object is something numeric, the function tries to convert it using #to_f method.
    • If that conversion fails (this happens for instance when the numeric is a complex) it returns RUBY_Qnil.
    • Otherwise returns the conversion result.
  • Otherwise it also returns RUBY_Qnil.
Parameters
[in]valAn object to convert.
Return values
RUBY_QnilConversion from val to float is undefined.
otherwiseConverted result.

Definition at line 3634 of file object.c.

◆ rb_check_to_int()

VALUE rb_check_to_int ( VALUE  val)

Identical to rb_check_to_integer(), except it uses #to_int for conversion.

Parameters
[in]valAn object to convert.
Exceptions
rb_eTypeError#to_int does not return an integer.
Return values
RUBY_QnilNo conversion defined.
otherwiseAn instance of rb_cInteger.

Definition at line 3194 of file object.c.

◆ rb_check_to_integer()

VALUE rb_check_to_integer ( VALUE  val,
const char *  mid 
)

Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger.

Parameters
[in]valAn object to convert.
[in]midConversion method (e.g. "to_ary").
Exceptions
rb_eTypeErrorThe mid does not generate an integer.
Return values
RUBY_QnilNo conversion defined.
otherwiseAn instance of rb_cInteger.

Definition at line 3175 of file object.c.

Referenced by rb_io_extract_modeenc().

◆ rb_class_get_superclass()

VALUE rb_class_get_superclass ( VALUE  klass)

Returns the superclass of a class.

Parameters
[in]klassAn object of RClass.
Return values
RUBY_Qfalseklass has no super class.
otherwiseRaw superclass of klass
See also
rb_class_superclass

Q&A

  • Q: How can a class have no super class?
  • A: klass could be a module. Or it could be rb_cBasicObject.
  • Q: What do you mean by "raw" superclass?
  • A: This is a really good question. The answer is that this function returns something different from what you would normally expect. On occasions ruby inserts hidden classes in a hierarchy of class inheritance behind-the-scene. Such classes are called "iclass"es and distinguished using RUBY_T_ICLASS in C level. They are truly transparent from Ruby level but can be accessed from C, by using this API.

Definition at line 2171 of file object.c.

◆ rb_class_inherited_p()

VALUE rb_class_inherited_p ( VALUE  scion,
VALUE  ascendant 
)

Determines if the given two modules are relatives.

Parameters
[in]scionPossible subclass.
[in]ascendantPossible superclass.
Exceptions
rb_eTypeErrorascendant is not a module.
Return values
RUBY_Qtruescion inherits, or is equal to ascendant.
RUBY_Qfalseascendant inherits scion.
RUBY_QnilThey are not relatives.

Definition at line 1764 of file object.c.

◆ rb_class_new_instance()

VALUE rb_class_new_instance ( int  argc,
const VALUE argv,
VALUE  klass 
)

Allocates, then initialises an instance of the given class.

It first calls the passed class' allocator to obtain an uninitialised object, then calls its initialiser with the remaining arguments.

Parameters
[in]argcNumber of objects of argv.
[in]argvArguments passed to #initialize.
[in]klassAn instance of rb_cClass.
Exceptions
rb_eTypeErrorklass's allocator is undefined.
rb_eExceptionAny exceptions can happen inside.
Returns
An allocated new instance of klass.

Definition at line 2134 of file object.c.

Referenced by rb_exc_new(), rb_exc_new_str(), rb_exit(), rb_f_abort(), rb_name_error(), rb_name_error_str(), rb_struct_alloc(), rb_struct_new(), rb_syserr_new_str(), and rb_throw_obj().

◆ rb_class_new_instance_kw()

VALUE rb_class_new_instance_kw ( int  argc,
const VALUE argv,
VALUE  klass,
int  kw_splat 
)

Identical to rb_class_new_instance(), except you can specify how to handle the last element of the given array.

Parameters
[in]argcNumber of objects of argv.
[in]argvArbitrary number of method arguments.
[in]klassAn instance of rb_cClass.
[in]kw_splatHandling of keyword parameters:
  • RB_NO_KEYWORDS argv's last is not a keyword argument.
  • RB_PASS_KEYWORDS argv's last is a keyword argument.
  • RB_PASS_CALLED_KEYWORDS it depends if there is a passed block.
Exceptions
rb_eTypeErrorklass's allocator is undefined.
rb_eExceptionAny exceptions can happen inside.
Returns
An allocated new instance of klass.

Definition at line 2122 of file object.c.

Referenced by rb_class_new_instance().

◆ rb_class_new_instance_pass_kw()

VALUE rb_class_new_instance_pass_kw ( int  argc,
const VALUE argv,
VALUE  klass 
)

Identical to rb_class_new_instance(), except it passes the passed keywords if any to the #initialize method.

Parameters
[in]argcNumber of objects of argv.
[in]argvArbitrary number of method arguments.
[in]klassAn instance of rb_cClass.
Exceptions
rb_eTypeErrorklass's allocator is undefined.
rb_eExceptionAny exceptions can happen inside.
Returns
An allocated new instance of klass.
Note
This is the implementation of Object.new.

Definition at line 2111 of file object.c.

◆ rb_class_of()

static VALUE rb_class_of ( VALUE  obj)
inlinestatic

Object to class mapping function.

Every object have its class. This function obtains that.

Parameters
[in]objTarget object to query.
Returns
The class of the given object.

Definition at line 172 of file globals.h.

◆ rb_class_real()

VALUE rb_class_real ( VALUE  klass)

Finds a "real" class.

As the name implies there are class objects that are surreal. This function takes a class, traverses its ancestry tree, and returns its nearest ancestor which is neither a module nor a singleton class.

Parameters
[in]klassAn instance of rb_cClass.
Return values
RUBY_QfalseNo real class in klass' ancestry tree.
klassklass itself is a real class.
otherwiseNearest ancestor of klass who is real.

Definition at line 237 of file object.c.

Referenced by rb_class2name(), rb_class_name(), and rb_obj_class().

◆ rb_class_superclass()

VALUE rb_class_superclass ( VALUE  klass)

Returns the superclass of klass.

Queries the parent of the given class.

Equivalent to Class#superclass in Ruby.

It skips modules.

Parameters
[in]klassa Class object
Returns
the superclass, or Qnil if klass does not have a parent class.
See also
rb_class_get_superclass

Definition at line 2149 of file object.c.

◆ rb_convert_type()

VALUE rb_convert_type ( VALUE  val,
int  type,
const char *  name,
const char *  mid 
)

Converts an object into another type.

Calls the specified conversion method if necessary.

Parameters
[in]valAn object to convert.
[in]typeA value of enum ruby_value_type.
[in]nameName to display on error (e.g. "Array").
[in]midConversion method (e.g. "to_ary").
Exceptions
rb_eTypeErrorFailed to convert.
Returns
An object of the specified type.

Definition at line 3088 of file object.c.

◆ rb_cstr_to_dbl()

double rb_cstr_to_dbl ( const char *  str,
int  mode 
)

Converts a textual representation of a real number into a numeric, which is the nearest value that the return type can represent, of the value that the argument represents.

This is in fact a 2-in-1 function whose behaviour can be controlled using the second (mode) argument. If the mode is zero, this function is in "historical" mode which only understands "floating-constant" defined at ISO/IEC 9899:1990 section 6.1.3.1. If the mode is nonzero, it is in "extended" mode, which also accepts "hexadecimal-floating-constant" defined at ISO/IEC 9899:2018 section 6.4.4.2.

Parameters
[in]strA textual representation of a real number.
[in]modeConversion mode, as described above.
Exceptions
rb_eArgErrorMalformed str passed.
See also
https://bugs.ruby-lang.org/issues/2969
Note
Null pointers are allowed, and it returns 0.0 then.

Definition at line 3435 of file object.c.

◆ rb_eql()

int rb_eql ( VALUE  lhs,
VALUE  rhs 
)

Checks for equality of the passed objects, in terms of Object#eql?.

Parameters
[in]lhsComparison left hand side.
[in]rhsComparison right hand side.
Return values
non-zeroThey are equal.
0Otherwise.
Note
This function actually calls lhs.eql?(rhs) so you cannot implement your class' #eql? method using it.

Definition at line 192 of file object.c.

◆ rb_equal()

VALUE rb_equal ( VALUE  lhs,
VALUE  rhs 
)

This function is an optimised version of calling #==.

It checks equality between two objects by first doing a fast identity check using using C's == (same as BasicObject#equal?). If that check fails, it calls #== dynamically. This optimisation actually affects semantics, because when #== returns false for the same object obj, rb_equal(obj, obj) would still return true. This happens for Float::NAN, where Float::NAN == Float::NAN is false, but rb_equal(Float::NAN, Float::NAN) is true.

Parameters
[in]lhsComparison LHS.
[in]rhsComparison RHS.
Return values
RUBY_QtrueThey are the same.
RUBY_QfalseThey are different.

Definition at line 179 of file object.c.

Referenced by rb_ary_assoc(), rb_ary_delete(), rb_ary_includes(), rb_ary_rassoc(), rb_big_eq(), and rb_str_equal().

◆ rb_Float()

VALUE rb_Float ( VALUE  val)

This is the logic behind Kernel#Float.

Numeric types are converted directly to the nearest value that a Float can represent. Strings are interpreted strictly; only leading/trailing whitespaces are allowed except what strtod understands. Anything else are converted using #to_f.

This is slightly stricter than String#to_f.

Parameters
[in]valAn object to convert.
Exceptions
rb_eArgErrorMalformed val passed.
rb_eTypeErrorNo conversion defined.
Returns
An instance of rb_cFloat.

Definition at line 3595 of file object.c.

Referenced by rb_str_format().

◆ rb_Hash()

VALUE rb_Hash ( VALUE  val)

Equivalent to Kernel#Hash in Ruby.

This is the logic behind Kernel#Hash.

Definition at line 3793 of file object.c.

◆ rb_inspect()

VALUE rb_inspect ( VALUE  obj)

Generates a human-readable textual representation of the given object.

This is largely similar to Ruby level Object#inspect but not the same; it additionally escapes the inspection result so that the string be compatible with that of default internal (or default external, if absent).

Parameters
[in]objArbitrary ruby object.
Returns
An instance of rb_cString that represents obj.

Definition at line 680 of file object.c.

Referenced by rb_cmperr(), rb_p(), and rb_str_format().

◆ rb_Integer()

VALUE rb_Integer ( VALUE  val)

This is the logic behind Kernel#Integer.

Numeric types are converted directly, with floating point numbers being truncated. Strings are interpreted strictly; only leading/trailing whitespaces, plus/minus sign, radix indicators such as 0x, digits, and underscores are allowed. Anything else are converted by first trying #to_int, then #to_i.

This is slightly stricter than String#to_i.

Parameters
[in]valAn object to convert.
Exceptions
rb_eArgErrorMalformed val passed.
rb_eTypeErrorNo conversion defined.
Returns
An instance of rb_cInteger.

Definition at line 3263 of file object.c.

Referenced by rb_str_format().

◆ rb_num2dbl()

double rb_num2dbl ( VALUE  num)

Converts an instance of rb_cNumeric into C's double.

Parameters
[in]numSomething numeric.
Exceptions
rb_eTypeErrornum is not a numeric.
Returns
The passed value converted into C's double.

Definition at line 3686 of file object.c.

◆ rb_obj_alloc()

VALUE rb_obj_alloc ( VALUE  klass)

Allocates an instance of the given class.

Parameters
[in]klassA class to instantiate.
Exceptions
rb_eTypeErrorklass is not a class.
Returns
An allocated, not yet initialised instance of klass.
Note
It calls the allocator defined by rb_define_alloc_func(). You cannot use this function to define an allocator. Use TypedData_Make_Struct or others, instead.
Usually prefer rb_class_new_instance() to rb_obj_alloc() and rb_obj_call_init().
See also
rb_class_new_instance()
rb_obj_call_init()
rb_define_alloc_func()
TypedData_Make_Struct

Definition at line 2093 of file object.c.

Referenced by rb_catch(), and rb_range_new().

◆ rb_obj_class()

VALUE rb_obj_class ( VALUE  obj)

Queries the class of an object.

This is not always identical to RBASIC_CLASS(obj). It searches for the nearest ancestor skipping singleton classes or included modules.

Parameters
[in]objObject in question.
Returns
The object's class, in a normal sense.

Definition at line 247 of file object.c.

Referenced by rb_check_inheritable(), rb_cmperr(), rb_define_module_id_under(), rb_gc_register_address(), rb_hash_dup(), rb_io_descriptor(), rb_profile_frame_classpath(), rb_str_drop_bytes(), rb_str_dup(), rb_str_new_frozen(), rb_str_new_shared(), rb_str_new_with_class(), and rb_struct_members().

◆ rb_obj_clone()

VALUE rb_obj_clone ( VALUE  obj)

Produces a shallow copy of the given object.

Its list of instance variables are copied, but not the objects they reference. It also copies the frozen value state.

Parameters
[in]objArbitrary ruby object.
Exceptions
rb_eException#initialize_copy can raise anything.
Returns
A "clone" of obj.

Definition at line 521 of file object.c.

Referenced by rb_eval_string_wrap().

◆ rb_obj_dup()

VALUE rb_obj_dup ( VALUE  obj)

Duplicates the given object.

This does almost the same thing as rb_obj_clone() do. However it does not copy the singleton class (if any). It also doesn't copy frozen-ness.

Parameters
[in]objArbitrary ruby object.
Exceptions
rb_eException#initialize_copy can raise anything.
Returns
A shallow copy of obj.

Definition at line 576 of file object.c.

Referenced by rb_io_path().

◆ rb_obj_embedded_size()

size_t rb_obj_embedded_size ( uint32_t  numiv)

Internal header for Object.

Author
Ruby developers ruby-.nosp@m.core.nosp@m.@ruby.nosp@m.-lan.nosp@m.g.org

Definition at line 98 of file object.c.

◆ rb_obj_freeze()

VALUE rb_obj_freeze ( VALUE  obj)

Just calls rb_obj_freeze_inline() inside.

Does this make any sens to extension libraries?

Parameters
[out]objObject to freeze.
Returns
Verbatim obj.

Definition at line 1260 of file object.c.

Referenced by rb_ary_freeze(), rb_hash_freeze(), and rb_str_freeze().

◆ rb_obj_frozen_p()

VALUE rb_obj_frozen_p ( VALUE  obj)

Just calls RB_OBJ_FROZEN() inside.

Does this make any sens to extension libraries?

Parameters
[in]objObject in question.
Return values
RUBY_QtrueYes it is.
RUBY_QfalseNo it isn't.

Definition at line 1272 of file object.c.

◆ rb_obj_hide()

VALUE rb_obj_hide ( VALUE  obj)

Make the object invisible from Ruby code.

It is useful to let Ruby's GC manage your internal data structure – The object keeps being managed by GC, but ObjectSpace.each_object never yields the object.

Note that the object also lose a way to call a method on it.

Parameters
[out]objA Ruby object.
Returns
The passed object.
Postcondition
The object is destructively modified to be invisible.
See also
rb_obj_reveal

Definition at line 104 of file object.c.

◆ rb_obj_init_clone()

static VALUE rb_obj_init_clone ( int  argc,
VALUE argv,
VALUE  obj 
)
static

Default implementation of #initialize_clone

Parameters
[in]Thenumber of arguments
[in]Thearray of arguments
[in]objthe receiver being initialized

Definition at line 647 of file object.c.

◆ rb_obj_init_copy()

VALUE rb_obj_init_copy ( VALUE  obj,
VALUE  orig 
)

Default implementation of #initialize_copy

Default implementation of #initialize_copy, #initialize_dup and #initialize_clone.

Parameters
[in,out]objthe receiver being initialized
[in]origthe object to be copied from.

Definition at line 616 of file object.c.

◆ rb_obj_init_dup_clone()

VALUE rb_obj_init_dup_clone ( VALUE  obj,
VALUE  orig 
)

Default implementation of #initialize_dup

Parameters
[in,out]objthe receiver being initialized
[in]origthe object to be dup from.

Definition at line 633 of file object.c.

◆ rb_obj_is_instance_of()

VALUE rb_obj_is_instance_of ( VALUE  obj,
VALUE  klass 
)

Queries if the given object is a direct instance of the given class.

Parameters
[in]objArbitrary ruby object.
[in]klassAn instance of rb_cModule.
Exceptions
rb_eTypeErrorklass is neither module nor class.
Return values
RUBY_Qtrueobj is an instance of klass.
RUBY_QfalseOtherwise.

Definition at line 809 of file object.c.

◆ rb_obj_is_kind_of()

VALUE rb_obj_is_kind_of ( VALUE  obj,
VALUE  klass 
)

Queries if the given object is an instance (of possibly descendants) of the given class.

Parameters
[in]objArbitrary ruby object.
[in]klassAn instance of rb_cModule.
Exceptions
rb_eTypeErrorklass is neither module nor class.
Return values
RUBY_Qtrueobj is a klass.
RUBY_QfalseOtherwise.

Definition at line 865 of file object.c.

Referenced by rb_arithmetic_sequence_extract(), rb_check_to_float(), rb_enumeratorize_with_size_kw(), rb_range_values(), rb_set_errinfo(), rb_struct_initialize(), and rb_vrescue2().

◆ rb_obj_reveal()

VALUE rb_obj_reveal ( VALUE  obj,
VALUE  klass 
)

Make a hidden object visible again.

It is the caller's responsibility to pass the right klass which obj originally used to belong to.

Parameters
[out]objA Ruby object.
[in]klassClass of obj.
Returns
Passed obj.
Precondition
obj was previously hidden.
Postcondition
obj's class is klass.
See also
rb_obj_hide

Definition at line 113 of file object.c.

◆ rb_obj_setup()

VALUE rb_obj_setup ( VALUE  obj,
VALUE  klass,
VALUE  type 
)

Fills common fields in the object.

Parameters
[in,out]objA Ruby object to be set up.
[in]klassobj will belong to this class.
[in]typeOne of ruby_value_type.
Returns
The passed object.

Definition at line 152 of file object.c.

◆ rb_str_to_dbl()

double rb_str_to_dbl ( VALUE  str,
int  mode 
)

Identical to rb_cstr_to_dbl(), except it accepts a Ruby's string instead of C's.

Parameters
[in]strA textual representation of a real number.
[in]modeConversion mode, as described in rb_cstr_to_dbl().
Exceptions
rb_eArgErrorMalformed str passed.
See also
https://bugs.ruby-lang.org/issues/2969

Definition at line 3479 of file object.c.

◆ rb_String()

VALUE rb_String ( VALUE  val)

This is the logic behind Kernel#String.

Arguments are converted by first trying #to_str, then #to_s.

Parameters
[in]valAn object to convert.
Exceptions
rb_eTypeErrorNo conversion defined.
Returns
An instance of rb_cString.

Definition at line 3718 of file object.c.

◆ rb_to_float()

VALUE rb_to_float ( VALUE  val)

Identical to rb_check_to_float(), except it raises on error.

Parameters
[in]valAn object to convert.
Exceptions
rb_eTypeErrorNo conversion defined.
Returns
An instance of rb_cFloat.

Definition at line 3624 of file object.c.

◆ rb_to_int()

VALUE rb_to_int ( VALUE  val)

Identical to rb_check_to_int(), except it raises in case of conversion mismatch.

Parameters
[in]valAn object to convert.
Exceptions
rb_eTypeError#to_int does not generate an integer.
Returns
An instance of rb_cInteger.

Definition at line 3188 of file object.c.

Referenced by rb_absint_singlebit_p(), rb_absint_size(), rb_big_lshift(), rb_big_rshift(), rb_integer_pack(), rb_io_extract_modeenc(), rb_num2long(), rb_random_ulong_limited(), and rb_rational_raw().

Variable Documentation

◆ rb_cArray

VALUE rb_cArray
extern

Array class.

Definition at line 40 of file array.c.

Referenced by rb_ary_new_capa(), rb_ary_new_from_values(), rb_ary_resurrect(), and rb_ary_sort_bang().

◆ rb_cBasicObject [1/2]

VALUE rb_cBasicObject
extern

BasicObject class.

Definition at line 64 of file object.c.

Referenced by Init_class_hierarchy(), and rb_class_superclass().

◆ rb_cBasicObject [2/2]

VALUE rb_cBasicObject

BasicObject class.

Definition at line 64 of file object.c.

Referenced by Init_class_hierarchy(), and rb_class_superclass().

◆ rb_cBinding

VALUE rb_cBinding
extern

Binding class.

Definition at line 43 of file proc.c.

◆ rb_cClass [1/2]

VALUE rb_cClass
extern

Class class.

Definition at line 68 of file object.c.

Referenced by rb_check_inheritable(), and rb_class_boot().

◆ rb_cClass [2/2]

VALUE rb_cClass

Class class.

Definition at line 68 of file object.c.

Referenced by rb_check_inheritable(), and rb_class_boot().

◆ rb_cComplex

VALUE rb_cComplex
extern

Complex class.

Definition at line 39 of file complex.c.

Referenced by rb_Complex(), rb_complex_new(), rb_complex_new_polar(), and rb_complex_raw().

◆ rb_cDir

VALUE rb_cDir
extern

Dir class.

Definition at line 504 of file dir.c.

◆ rb_cEncoding [1/2]

VALUE rb_cEncoding
extern

Encoding class.

Definition at line 57 of file encoding.c.

◆ rb_cEncoding [2/2]

VALUE rb_cEncoding
extern

Encoding class.

Definition at line 57 of file encoding.c.

◆ rb_cEnumerator

VALUE rb_cEnumerator
extern

Enumerator class.

Definition at line 163 of file enumerator.c.

Referenced by rb_enumeratorize_with_size_kw().

◆ rb_cFalseClass [1/2]

VALUE rb_cFalseClass
extern

FalseClass class.

Definition at line 73 of file object.c.

Referenced by rb_class_of().

◆ rb_cFalseClass [2/2]

VALUE rb_cFalseClass

FalseClass class.

Definition at line 73 of file object.c.

Referenced by rb_class_of().

◆ rb_cFile

VALUE rb_cFile
extern

File class.

Definition at line 175 of file file.c.

Referenced by rb_file_open(), rb_file_open_str(), and rb_io_fdopen().

◆ rb_cFloat

VALUE rb_cFloat
extern

Float class.

Definition at line 197 of file numeric.c.

Referenced by rb_class_of(), and rb_float_new_in_heap().

◆ rb_cHash

VALUE rb_cHash
extern

Hash class.

Definition at line 113 of file hash.c.

Referenced by rb_hash_new().

◆ rb_cInteger

VALUE rb_cInteger
extern

Module class.

Definition at line 198 of file numeric.c.

Referenced by rb_class_of().

◆ rb_cIO

VALUE rb_cIO
extern

IO class.

Definition at line 187 of file io.c.

Referenced by rb_io_fdopen().

◆ rb_cMatch

VALUE rb_cMatch
extern

MatchData class.

Definition at line 967 of file re.c.

◆ rb_cMethod

VALUE rb_cMethod
extern

Method class.

Definition at line 42 of file proc.c.

◆ rb_cModule [1/2]

VALUE rb_cModule
extern

Module class.

Definition at line 67 of file object.c.

◆ rb_cModule [2/2]

VALUE rb_cModule

Module class.

Definition at line 67 of file object.c.

◆ rb_cNameErrorMesg

VALUE rb_cNameErrorMesg
extern

NameError::Message class.

Definition at line 1420 of file error.c.

◆ rb_cNilClass [1/2]

VALUE rb_cNilClass
extern

NilClass class.

Definition at line 71 of file object.c.

Referenced by rb_class_of().

◆ rb_cNilClass [2/2]

VALUE rb_cNilClass

NilClass class.

Definition at line 71 of file object.c.

Referenced by rb_class_of().

◆ rb_cNumeric

VALUE rb_cNumeric
extern

Numeric class.

Definition at line 196 of file numeric.c.

Referenced by rb_check_to_float().

◆ rb_cObject [1/2]

VALUE rb_cObject
extern

Object class.

Object class.

Definition at line 66 of file object.c.

◆ rb_cObject [2/2]

VALUE rb_cObject

Documented in include/ruby/internal/globals.h.

Object class.

Definition at line 66 of file object.c.

◆ rb_cProc

VALUE rb_cProc
extern

Proc class.

Definition at line 44 of file proc.c.

Referenced by rb_block_lambda(), and rb_block_proc().

◆ rb_cRactor

VALUE rb_cRactor
extern

Ractor class.

Definition at line 23 of file ractor.c.

◆ rb_cRandom

VALUE rb_cRandom
extern

Random class.

Definition at line 236 of file random.c.

◆ rb_cRange

VALUE rb_cRange
extern

Range class.

Definition at line 31 of file range.c.

Referenced by rb_range_new(), and rb_range_values().

◆ rb_cRational

VALUE rb_cRational
extern

Rational class.

Definition at line 53 of file rational.c.

Referenced by rb_Rational(), rb_rational_new(), and rb_rational_raw().

◆ rb_cRefinement [1/2]

VALUE rb_cRefinement
extern

Refinement class.

Definition at line 69 of file object.c.

◆ rb_cRefinement [2/2]

VALUE rb_cRefinement

Refinement class.

Definition at line 69 of file object.c.

◆ rb_cRegexp

VALUE rb_cRegexp
extern

Regexp class.

Definition at line 2640 of file re.c.

◆ rb_cStat

VALUE rb_cStat
extern

File::Stat class.

Definition at line 177 of file file.c.

Referenced by rb_stat_new().

◆ rb_cString

VALUE rb_cString
extern

◆ rb_cStruct

VALUE rb_cStruct
extern

Struct class.

Definition at line 33 of file struct.c.

Referenced by rb_struct_define(), and rb_struct_define_under().

◆ rb_cSymbol

VALUE rb_cSymbol
extern

Symbol class.

Definition at line 79 of file string.c.

Referenced by rb_class_of(), and rb_str_intern().

◆ rb_cThread

VALUE rb_cThread
extern

Thread class.

Definition at line 543 of file vm.c.

◆ rb_cTime

VALUE rb_cTime
extern

Time class.

Definition at line 672 of file time.c.

Referenced by rb_time_interval(), rb_time_nano_new(), rb_time_new(), and rb_time_timespec_new().

◆ rb_cTrueClass [1/2]

VALUE rb_cTrueClass
extern

TrueClass class.

Definition at line 72 of file object.c.

Referenced by rb_class_of().

◆ rb_cTrueClass [2/2]

VALUE rb_cTrueClass

TrueClass class.

Definition at line 72 of file object.c.

Referenced by rb_class_of().

◆ rb_cUnboundMethod

VALUE rb_cUnboundMethod
extern

UnboundMethod class.

Definition at line 41 of file proc.c.

◆ rb_mComparable

VALUE rb_mComparable
extern

Comparable module.

Definition at line 19 of file compar.c.

◆ rb_mEnumerable

VALUE rb_mEnumerable
extern

Enumerable module.

Definition at line 27 of file enum.c.

◆ rb_mErrno

VALUE rb_mErrno
extern

Errno module.

Definition at line 1429 of file error.c.

◆ rb_mFileTest

VALUE rb_mFileTest
extern

FileTest module.

Definition at line 176 of file file.c.

◆ rb_mGC

VALUE rb_mGC
extern

GC module.

Definition at line 371 of file gc.c.

◆ rb_mKernel [1/2]

VALUE rb_mKernel
extern

Kernel module.

Definition at line 65 of file object.c.

Referenced by rb_define_global_function().

◆ rb_mKernel [2/2]

VALUE rb_mKernel

Kernel module.

Definition at line 65 of file object.c.

Referenced by rb_define_global_function().

◆ rb_mMath

VALUE rb_mMath
extern

Math module.

Definition at line 29 of file math.c.

◆ rb_mProcess

VALUE rb_mProcess
extern

Process module.

Definition at line 8819 of file process.c.

Referenced by ruby_prog_init().

◆ rb_mWaitReadable

VALUE rb_mWaitReadable
extern

IO::WaitReadable module.

Definition at line 191 of file io.c.

◆ rb_mWaitWritable

VALUE rb_mWaitWritable
extern

IO::WaitReadable module.

Definition at line 192 of file io.c.

◆ rb_stderr

VALUE rb_stderr
extern

STDERR constant.

Definition at line 201 of file io.c.

Referenced by rb_ractor_stderr(), and rb_ractor_stderr_set().

◆ rb_stdin

VALUE rb_stdin
extern

STDIN constant.

Definition at line 201 of file io.c.

Referenced by rb_ractor_stdin(), and rb_ractor_stdin_set().

◆ rb_stdout

VALUE rb_stdout
extern

STDOUT constant.

Definition at line 201 of file io.c.

Referenced by rb_ractor_stdout(), and rb_ractor_stdout_set().