Ruby: Core objects and their operations

Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)

Data Structures | Macros | Functions | Variables
Core objects and their operations

## Macros
#define | case_equal rb_equal
| call-seq: obj === other -> true or false More...
#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 | opts_exception_p(opts) rb_opts_exception_p((opts), TRUE)

## Functions
void | rb_obj_call_init (VALUE obj, int argc, const VALUE *argv)
| Calls `initialize` method of obj with the given arguments. 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_obj_setup (VALUE obj, VALUE klass, VALUE type)
| Fills common (`RBasic`) fields in obj. More...
VALUE | rb_equal (VALUE obj1, VALUE obj2)
| This function is an optimized version of calling #==. More...
int | rb_eql (VALUE obj1, VALUE obj2)
| Determines if obj1 and obj2 are equal in terms of `Object::eql`?. More...
VALUE | rb_obj_hash (VALUE obj)
VALUE | rb_class_real (VALUE cl)
| Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions. More...
VALUE | rb_obj_class (VALUE obj)
VALUE | rb_obj_clone (VALUE obj)
| Almost same as `Object::clone`. More...
VALUE | rb_obj_dup (VALUE obj)
| Equivalent to `Object#dup` in Ruby. More...
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...
VALUE | rb_any_to_s (VALUE obj)
| Default implementation of `#to_s`. More...
VALUE | rb_str_escape (VALUE str)
VALUE | rb_inspect (VALUE obj)
| Convenient wrapper of `Object::inspect`. More...
VALUE | rb_obj_is_instance_of (VALUE obj, VALUE c)
| Determines if obj is an instance of c. More...
VALUE | rb_obj_is_kind_of (VALUE obj, VALUE c)
| Determines if obj is a kind of c. More...
VALUE | rb_obj_tainted (VALUE obj)
| call-seq: obj.tainted? -> false More...
VALUE | rb_obj_taint (VALUE obj)
| call-seq: obj.taint -> obj More...
VALUE | rb_obj_untaint (VALUE obj)
| call-seq: obj.untaint -> obj More...
VALUE | rb_obj_untrusted (VALUE obj)
| call-seq: obj.untrusted? -> false More...
VALUE | rb_obj_untrust (VALUE obj)
| call-seq: obj.untrust -> obj More...
VALUE | rb_obj_trust (VALUE obj)
| call-seq: obj.trust -> obj More...
void | rb_obj_infect (VALUE victim, VALUE carrier)
| Does nothing. More...
VALUE | rb_obj_freeze (VALUE obj)
| Make the object unmodifiable. More...
VALUE | rb_obj_frozen_p (VALUE obj)
VALUE | rb_false (VALUE obj)
VALUE | rb_class_inherited_p (VALUE mod, VALUE arg)
| Determines if mod inherits arg. More...
VALUE | rb_obj_alloc (VALUE klass)
| Allocates an instance of klass. More...
VALUE | rb_class_new_instance_pass_kw (int argc, const VALUE *argv, VALUE klass)
VALUE | rb_class_new_instance_kw (int argc, const VALUE *argv, VALUE klass, int kw_splat)
VALUE | rb_class_new_instance (int argc, const VALUE *argv, VALUE klass)
| Allocates and initializes an instance of klass. More...
VALUE | rb_class_superclass (VALUE klass)
| Returns the superclass of klass. More...
VALUE | rb_class_get_superclass (VALUE klass)
| Returns the superclass of klass The return value might be an iclass of a module, unlike rb_class_superclass. More...
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)
| Tries to convert an object into another type. More...
VALUE | rb_check_to_integer (VALUE val, const char *method)
| Tries to convert val into `Integer`. More...
VALUE | rb_to_int (VALUE val)
| Converts val into `Integer`. More...
VALUE | rb_check_to_int (VALUE val)
| Tries to convert val into Integer. More...
VALUE | rb_Integer (VALUE val)
| Equivalent to `Kernel#Integer` in Ruby. More...
int | rb_bool_expected (VALUE obj, const char *flagname)
int | rb_opts_exception_p (VALUE opts, int default_value)
double | rb_cstr_to_dbl (const char *p, int badcheck)
| Parses a string representation of a floating point number. More...
| FUNC_MINIMIZED (double rb_str_to_dbl(VALUE str, int badcheck))
double | rb_str_to_dbl (VALUE str, int badcheck)
| Parses a string representation of a floating point number. More...
| FUNC_MINIMIZED (VALUE rb_Float(VALUE val))
VALUE | rb_Float (VALUE val)
| Equivalent to `Kernel#Float` in Ruby. More...
VALUE | rb_to_float (VALUE val)
| Converts a `Numeric` object into `Float`. More...
VALUE | rb_check_to_float (VALUE val)
| Tries to convert an object into `Float`. More...
double | rb_num2dbl (VALUE val)
| Converts a `Numeric` object to `double`. More...
VALUE | rb_String (VALUE val)
| Equivalent to `Kernel#String` in Ruby. More...
VALUE | rb_Array (VALUE val)
| Equivalent to `Kernel#Array` in Ruby. More...
VALUE | rb_Hash (VALUE val)
| Equivalent to `Kernel#Hash` in Ruby. More...
void | Init_Object (void)

## Variables
VALUE | rb_cBasicObject
| BasicObject class. More...
VALUE | rb_mKernel
| Kernel module. More...
VALUE | rb_cObject
| Object class. More...
VALUE | rb_cModule
| Module class. More...
VALUE | rb_cClass
| Class class. More...
VALUE | rb_cNilClass
| NilClass class. More...
VALUE | rb_cTrueClass
| TrueClass class. More...
VALUE | rb_cFalseClass
| FalseClass class. More...

## Detailed Description

## Macro Definition Documentation

## ◆ case_equal

#define case_equal rb_equal

call-seq: obj === other -> true or false

Case Equality – For class Object, effectively the same as calling `#==`, but typically overridden by descendants to provide meaningful semantics in +case+ statements.

Definition at line 141 of file object.c.

## ◆ false_or

#define false_or true_and

Definition at line 1355 of file object.c.

## ◆ false_xor

#define false_xor true_and

Definition at line 1368 of file object.c.

## ◆ id_for_setter

#define id_for_setter | ( |  | obj,
|  |  | name,
|  |  | type,
|  |  | message
| ) |  | check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))

Definition at line 2013 of file object.c.

## ◆ id_for_var

#define id_for_var | ( |  | obj,
|  |  | name,
|  |  | type
| ) |  | id_for_setter(obj, name, type, bad_##type##_name)

Definition at line 2011 of file object.c.

## ◆ IMPLICIT_CONVERSIONS

#define IMPLICIT_CONVERSIONS 7

Definition at line 2851 of file object.c.

## ◆ opts_exception_p

#define opts_exception_p | ( |  | opts | ) | rb_opts_exception_p((opts), TRUE)

Definition at line 3166 of file object.c.

## ◆ try_to_int

#define try_to_int | ( |  | val,
|  |  | mid,
|  |  | raise
| ) |  | convert_type_with_id(val, "Integer", mid, raise, -1)

Definition at line 3001 of file object.c.

## ◆ wrong_constant_name

#define wrong_constant_name bad_const_name

Definition at line 2008 of file object.c.

## Function Documentation

## ◆ FUNC_MINIMIZED() [1/2]

FUNC_MINIMIZED | ( | double | rb_str_to_dblVALUE str, int badcheck | ) |

## ◆ FUNC_MINIMIZED() [2/2]

FUNC_MINIMIZED | ( | VALUE | rb_FloatVALUE val | ) |

## ◆ Init_Object()

void Init_Object | ( | void |  | ) |

Definition at line 4474 of file object.c.

References InitVM.

## ◆ rb_any_to_s()

VALUE rb_any_to_s | ( | VALUE | obj | ) |

Default implementation of `#to_s`.

Definition at line 561 of file object.c.

References CLASS_OF, PRIsVALUE, rb_class_name(), rb_sprintf(), and str.

Referenced by rb_int2str(), and rb_obj_as_string_result().

## ◆ rb_Array()

VALUE rb_Array | ( | VALUE | val | ) |

Equivalent to `Kernel#Array` in Ruby.

Definition at line 3705 of file object.c.

References NIL_P, rb_ary_new3, rb_check_array_type(), and rb_check_to_array().

## ◆ rb_bool_expected()

int rb_bool_expected | ( | VALUE | obj,
|  | const char * | flagname
| ) |  |

Definition at line 3144 of file object.c.

References PRIsVALUE, Qfalse, Qtrue, rb_eArgError, and rb_raise().

Referenced by rb_opts_exception_p().

## ◆ rb_check_convert_type()

VALUE rb_check_convert_type | ( | VALUE | val,
|  | int | type,
|  | const char * | tname,
|  | const char * | method
| ) |  |

Tries to convert an object into another type.

Calls the specified conversion method if necessary.

Parameters

  [in] | val | the object to be converted
  [in] | type | a value of `ruby_value_type`
  [in] | tname | name of the target type. only used for error messages.
  [in] | method | name of the method

Returns
  an object of the specified type, or Qnil if no such conversion method defined.

Exceptions

  TypeError | if the conversion method returns an unexpected type of value.

See also
  rb_convert_type
  rb_check_convert_type_with_id

Definition at line 2971 of file object.c.

References FALSE, NIL_P, Qnil, T_DATA, and TYPE.

Referenced by rb_check_regexp_type().

## ◆ rb_check_to_float()

VALUE rb_check_to_float | ( | VALUE | val | ) |

Tries to convert an object into `Float`.

It calls `#to_f` if necessary.

It returns `Qnil` if the object is not a `Numeric` or `#to_f` is not defined on the object.

Definition at line 3576 of file object.c.

References id_to_f, Qnil, rb_check_convert_type_with_id(), rb_cNumeric, rb_obj_is_kind_of(), and T_FLOAT.

## ◆ rb_check_to_int()

VALUE rb_check_to_int | ( | VALUE | val | ) |

Tries to convert val into Integer.

It calls `#to_int` method if necessary.

Parameters

  [in] | val | a Ruby object

Returns
  an Integer object on success, or `Qnil` if `#to_int` is not defined.

Exceptions

  TypeError | if `#to_int` returns a non-Integer object.

Definition at line 3066 of file object.c.

References FALSE, Qnil, RB_INTEGER_TYPE_P, and try_to_int.

## ◆ rb_check_to_integer()

VALUE rb_check_to_integer | ( | VALUE | val,
|  | const char * | method
| ) |  |

Tries to convert val into `Integer`.

It calls the specified conversion method if necessary.

Parameters

  [in] | val | a Ruby object
  [in] | method | a name of a method

Returns
  an `Integer` object on success, or `Qnil` if no such conversion method defined.

Exceptions

  TypeError | if the conversion method returns a non-Integer object.

Definition at line 3029 of file object.c.

References FALSE, FIXNUM_P, Qnil, RB_INTEGER_TYPE_P, and T_BIGNUM.

Referenced by rb_io_extract_modeenc().

## ◆ rb_class_get_superclass()

VALUE rb_class_get_superclass | ( | VALUE | klass | ) |

Returns the superclass of klass The return value might be an iclass of a module, unlike rb_class_superclass.

Also it returns Qfalse when klass does not have a parent class.

See also
  rb_class_superclass

Definition at line 1999 of file object.c.

References RCLASS.

## ◆ rb_class_inherited_p()

VALUE rb_class_inherited_p | ( | VALUE | mod,
|  | VALUE | arg
| ) |  |

Determines if mod inherits arg.

Equivalent to `Module#<=` in Ruby

Parameters

  [in] | mod | a Module object
  [in] | arg | another Module object or an iclass of a module

Return values

  Qtrue | if mod inherits arg, or mod equals arg
  Qfalse | if arg inherits mod
  Qnil | if otherwise

Definition at line 1578 of file object.c.

References CLASS_OR_MODULE_P, mod, Qfalse, Qnil, Qtrue, rb_eTypeError, rb_raise(), RCLASS_ORIGIN, and T_ICLASS.

## ◆ rb_class_new_instance()

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

Allocates and initializes an instance of klass.

Equivalent to `Class#new` in Ruby

Parameters

  [in] | argc | the number of arguments to `initialize`
  [in] | argv | a pointer to an array of arguments to `initialize`
  [in] | klass | a Class object

Returns
  the new instance of klass

See also
  rb_obj_call_init
  rb_obj_alloc

Definition at line 1953 of file object.c.

References argc, argv, RB_NO_KEYWORDS, rb_obj_call_init_kw(), and T_CLASS.

Referenced by Init_Exception(), Init_IO(), Init_Regexp(), rb_exc_new(), rb_exc_new_str(), rb_exit(), rb_f_abort(), rb_fiddle_new_function(), rb_name_error(), rb_name_error_str(), rb_readwrite_syserr_fail(), rb_struct_alloc(), rb_struct_new(), rb_syntax_error_append(), 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
| ) |  |

Definition at line 1929 of file object.c.

References argc, argv, rb_obj_call_init_kw(), and T_CLASS.

## ◆ rb_class_new_instance_pass_kw()

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

Definition at line 1918 of file object.c.

References argc, argv, rb_obj_call_init_kw(), and RB_PASS_CALLED_KEYWORDS.

## ◆ rb_class_real()

VALUE rb_class_real | ( | VALUE | cl | ) |

Looks up the nearest ancestor of cl, skipping singleton classes or module inclusions.

It returns the cl itself if it is neither a singleton class or a module.

Parameters

  [in] | cl | a Class object.

Returns
  the ancestor class found, or Qfalse if nothing found.

Definition at line 235 of file object.c.

References BUILTIN_TYPE, FL_SINGLETON, RBASIC, RCLASS_SUPER, and T_ICLASS.

Referenced by rb_class2name(), rb_class_name(), rb_define_class(), rb_define_class_id_under(), rb_obj_class(), rb_vm_bugreport(), and ruby_vm_special_exception_copy().

## ◆ rb_class_superclass()

VALUE rb_class_superclass | ( | VALUE | klass | ) |

Returns the superclass of klass.

Equivalent to `Class#superclass` in Ruby.

It skips modules.

Parameters

  [in] | klass | a Class object

Returns
  the superclass, or `Qnil` if klass does not have a parent class.

See also
  rb_class_get_superclass

Definition at line 1974 of file object.c.

References Qnil, rb_cBasicObject, rb_eTypeError, rb_raise(), RCLASS_SUPER, and T_ICLASS.

## ◆ rb_convert_type()

VALUE rb_convert_type | ( | VALUE | val,
|  | int | type,
|  | const char * | tname,
|  | const char * | method
| ) |  |

Converts an object into another type.

Calls the specified conversion method if necessary.

Parameters

  [in] | val | the object to be converted
  [in] | type | a value of `ruby_value_type`
  [in] | tname | name of the target type. only used for error messages.
  [in] | method | name of the method

Returns
  an object of the specified type

Exceptions

  TypeError | on failure

See also
  rb_check_convert_type

Definition at line 2930 of file object.c.

References TRUE, and TYPE.

Referenced by rb_numeric_quo().

## ◆ rb_cstr_to_dbl()

double rb_cstr_to_dbl | ( | const char * | p,
|  | int | badcheck
| ) |  |

Parses a string representation of a floating point number.

Parameters

  [in] | p | a string representation of a floating number
  [in] | badcheck | raises an exception on parse error if badcheck is non-zero.

Returns
  the floating point number in the string on success, 0.0 on parse error and badcheck is zero.

Note
  it always fails to parse a hexadecimal representation like "0xAB.CDp+1" when badcheck is zero, even though it would success if badcheck was non-zero. This inconsistency is coming from a historical compatibility reason. [ruby-dev:40822]

Definition at line 3357 of file object.c.

References NULL, and TRUE.

## ◆ rb_eql()

int rb_eql | ( | VALUE | obj1,
|  | VALUE | obj2
| ) |  |

Determines if obj1 and obj2 are equal in terms of `Object::eql`?.

Note
  It actually calls `#eql`? when necessary. So you cannot implement `#eql`? with this function.

Return values

  non-zero | if they are eql?
  zero | if they are not eql?.

Definition at line 180 of file object.c.

References Qfalse, Qtrue, Qundef, rb_eql_opt(), rb_funcall(), and RTEST.

## ◆ rb_equal()

VALUE rb_equal | ( | VALUE | obj1,
|  | VALUE | obj2
| ) |  |

This function is an optimized 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 optimization 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.

Definition at line 157 of file object.c.

References id_eq, Qfalse, Qtrue, Qundef, rb_equal_opt(), rb_funcall(), and RTEST.

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

## ◆ rb_false()

VALUE rb_false | ( | VALUE | obj | ) |

Definition at line 1395 of file object.c.

References Qfalse.

Referenced by rb_vm_opt_cfunc_p().

## ◆ rb_Float()

VALUE rb_Float | ( | VALUE | val | ) |

Equivalent to `Kernel#Float` in Ruby.

Converts val into `Float` in a slightly more strict manner than `#to_f`.

Definition at line 3531 of file object.c.

References TRUE.

Referenced by rb_str_format().

## ◆ rb_Hash()

VALUE rb_Hash | ( | VALUE | val | ) |

Equivalent to `Kernel#Hash` in Ruby.

Definition at line 3748 of file object.c.

References NIL_P, RARRAY_LEN, rb_check_hash_type(), rb_eTypeError, rb_hash_new(), rb_obj_classname(), rb_raise(), and T_ARRAY.

## ◆ rb_inspect()

VALUE rb_inspect | ( | VALUE | obj | ) |

Convenient wrapper of `Object::inspect`.

Returns a human-readable string representation of obj, similarly to `Object::inspect`.

Unlike Ruby-level `#inspect`, it escapes characters to keep the result compatible to the default internal or external encoding. If the default internal or external encoding is ASCII compatible, the encoding of the inspected result must be compatible with it. If the default internal or external encoding is ASCII incompatible, the result must be ASCII only.

Definition at line 585 of file object.c.

References NULL, rb_default_external_encoding(), rb_default_internal_encoding(), rb_enc_asciicompat, rb_enc_get(), rb_enc_str_asciionly_p(), rb_funcallv, rb_obj_as_string(), rb_str_escape(), and str.

Referenced by rb_cmperr(), rb_dump_literal(), rb_insn_operand_intern(), rb_keyword_error_new(), rb_p(), rb_str_format(), rb_vmdebug_debug_print_post(), and rb_vmdebug_proc_dump_raw().

## ◆ rb_Integer()

VALUE rb_Integer | ( | VALUE | val | ) |

Equivalent to `Kernel#Integer` in Ruby.

Converts val into `Integer` in a slightly more strict manner than `to_i`.

Definition at line 3138 of file object.c.

References TRUE.

Referenced by ossl_time_split(), rb_fiddle_value_to_generic(), and rb_str_format().

## ◆ rb_num2dbl()

double rb_num2dbl | ( | VALUE | val | ) |

Converts a `Numeric` object to `double`.

Parameters

  [in] | val | a `Numeric` object

Returns
  the converted value

Exceptions

  TypeError | if val is not a `Numeric` or it does not support conversion to a floating point number.

Definition at line 3635 of file object.c.

References BUILTIN_TYPE, FIXNUM_P, id_to_f, rb_convert_type_with_id(), rb_eTypeError, rb_raise(), RFLOAT_VALUE, SPECIAL_CONST_P, T_BIGNUM, T_FLOAT, T_RATIONAL, and T_STRING.

## ◆ rb_obj_alloc()

VALUE rb_obj_alloc | ( | VALUE | klass | ) |

Allocates an instance of klass.

Note
  It calls the allocator defined by {rb_define_alloc_func}. So you cannot use this function to define an allocator. Use {rb_newobj_of}, {TypedData_Make_Struct} or others, instead.
  Usually prefer rb_class_new_instance to rb_obj_alloc and rb_obj_call_init

Parameters

  [in] | klass | a Class object

See also
  rb_class_new_instance
  rb_obj_call_init
  rb_define_alloc_func
  rb_newobj_of
  TypedData_Make_Struct

Definition at line 1900 of file object.c.

References T_CLASS.

Referenced by Init_Hash(), Init_readline(), Init_Thread(), Init_top_self(), Init_VM(), rb_catch(), rb_key_err_new(), rb_name_err_new(), rb_nomethod_err_new(), rb_obj_dup(), rb_range_new(), rsock_s_accept(), rsock_s_accept_nonblock(), rsock_sockopt_new(), and ruby_vm_special_exception_copy().

## ◆ rb_obj_call_init()

void rb_obj_call_init | ( | VALUE | obj,
|  | int | argc,
|  | const VALUE * | argv
| ) |  |

Calls `initialize` method of obj with the given arguments.

It also forwards the given block to `initialize` if given.

Parameters

  [in] | obj | the receiver object
  [in] | argc | the number of arguments
  [in] | argv | a pointer to the array of arguments

Definition at line 1710 of file eval.c.

References argc, argv, PASS_PASSED_BLOCK_HANDLER, rb_funcallv_kw(), and RB_NO_KEYWORDS.

## ◆ rb_obj_class()

VALUE rb_obj_class | ( | VALUE | obj | ) |

Definition at line 245 of file object.c.

References CLASS_OF, and rb_class_real().

Referenced by BIGNUM_1c(), rb_block_to_s(), rb_check_inheritable(), rb_cmperr(), rb_copy_generic_ivar(), rb_define_class(), rb_define_class_id_under(), rb_define_module(), rb_define_module_id_under(), rb_hash_aset(), rb_hash_dup(), rb_obj_dup(), rb_obj_init_copy(), rb_obj_is_instance_of(), rb_profile_frame_classpath(), rb_str_dup(), rb_str_new_frozen(), rb_str_new_shared(), rb_str_new_with_class(), rb_struct_members(), and rb_vm_bugreport().

## ◆ rb_obj_clone()

VALUE rb_obj_clone | ( | VALUE | obj | ) |

Almost same as `Object::clone`.

Definition at line 457 of file object.c.

References Qnil.

Referenced by rb_eval_string_wrap().

## ◆ rb_obj_dup()

VALUE rb_obj_dup | ( | VALUE | obj | ) |

Equivalent to `Object#dup` in Ruby.

Definition at line 467 of file object.c.

References rb_funcall(), rb_obj_alloc(), and rb_obj_class().

## ◆ rb_obj_freeze()

VALUE rb_obj_freeze | ( | VALUE | obj | ) |

Make the object unmodifiable.

Equivalent to `Object#freeze` in Ruby.

Parameters

  [in,out] | obj | the object to be frozen

Returns
  the frozen object

Definition at line 1101 of file object.c.

References OBJ_FREEZE, OBJ_FROZEN, rb_bug(), and SPECIAL_CONST_P.

Referenced by Init_Exception(), Init_File(), Init_strscan(), Init_VM(), InitVM_Enumerator(), rb_ary_freeze(), rb_hash_freeze(), rb_insns_name_array(), rb_iseq_pathobj_new(), rb_process_status_new(), rb_reg_compile(), rb_reg_new_ary(), rb_str_freeze(), rb_vm_register_special_exception_str(), and yyparse().

## ◆ rb_obj_frozen_p()

VALUE rb_obj_frozen_p | ( | VALUE | obj | ) |

Definition at line 1113 of file object.c.

References OBJ_FROZEN, Qfalse, and Qtrue.

## ◆ rb_obj_hash()

VALUE rb_obj_hash | ( | VALUE | obj | ) |

Definition at line 305 of file hash.c.

References ST2FIX.

## ◆ 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

  [in] | obj | a Ruby object

See also
  rb_obj_reveal

Definition at line 92 of file object.c.

References SPECIAL_CONST_P.

Referenced by Init_sym(), rb_autoload_str(), and rb_default_coverage().

## ◆ rb_obj_infect()

void rb_obj_infect | ( | VALUE | victim,
|  | VALUE | carrier
| ) |  |

Does nothing.

This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1089 of file object.c.

References rb_warn_deprecated_to_remove().

## ◆ rb_obj_init_copy()

VALUE rb_obj_init_copy | ( | VALUE | obj,
|  | VALUE | orig
| ) |  |

Default implementation of `#initialize_copy`.

Parameters

  [in,out] | obj | the receiver being initialized
  [in] | orig | the object to be copied from.

Definition at line 516 of file object.c.

References rb_check_frozen, rb_eTypeError, rb_obj_class(), rb_raise(), and TYPE.

## ◆ rb_obj_init_dup_clone()

VALUE rb_obj_init_dup_clone | ( | VALUE | obj,
|  | VALUE | orig
| ) |  |

Default implementation of `#initialize_dup`.

Parameters

  [in,out] | obj | the receiver being initialized
  [in] | orig | the object to be dup from.

Definition at line 533 of file object.c.

References rb_funcall().

## ◆ rb_obj_is_instance_of()

VALUE rb_obj_is_instance_of | ( | VALUE | obj,
|  | VALUE | c
| ) |  |

Determines if obj is an instance of c.

Equivalent to `Object#is_instance_of` in Ruby.

Parameters

  [in] | obj | the object to be determined.
  [in] | c | a Class object

Definition at line 707 of file object.c.

References Qfalse, Qtrue, and rb_obj_class().

## ◆ rb_obj_is_kind_of()

VALUE rb_obj_is_kind_of | ( | VALUE | obj,
|  | VALUE | c
| ) |  |

Determines if obj is a kind of c.

Equivalent to `Object#kind_of`? in Ruby.

Parameters

  [in] | obj | the object to be determined
  [in] | c | a Module object.

Definition at line 724 of file object.c.

References CLASS_OF, Qfalse, Qtrue, and RCLASS_ORIGIN.

Referenced by EVENTSINK_Invoke(), ole_val2variant(), ossl_evp_get_cipherbyname(), rb_arithmetic_sequence_extract(), rb_check_to_float(), rb_enumeratorize_with_size(), rb_enumeratorize_with_size_kw(), rb_node_case_when_optimizable_literal(), rb_range_values(), rb_set_errinfo(), 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.

See also
  rb_obj_hide

Definition at line 109 of file object.c.

References SPECIAL_CONST_P.

## ◆ rb_obj_setup()

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

Fills common (`RBasic`) fields in obj.

Note
  Prefer rb_newobj_of() to this function.

Parameters

  [in,out] | obj | a Ruby object to be set up.
  [in] | klass | `obj` will belong to this class.
  [in] | type | one of `ruby_value_type`

Definition at line 126 of file object.c.

References RBASIC.

## ◆ rb_obj_size()

VALUE rb_obj_size | ( | VALUE | self,
|  | VALUE | args,
|  | VALUE | obj
| ) |  |

Definition at line 499 of file object.c.

References LONG2FIX.

## ◆ rb_obj_taint()

VALUE rb_obj_taint | ( | VALUE | obj | ) |

call-seq: obj.taint -> obj

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1020 of file object.c.

References rb_warn_deprecated_to_remove().

## ◆ rb_obj_tainted()

VALUE rb_obj_tainted | ( | VALUE | obj | ) |

call-seq: obj.tainted? -> false

Returns false. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1006 of file object.c.

References Qfalse, and rb_warn_deprecated_to_remove().

## ◆ rb_obj_trust()

VALUE rb_obj_trust | ( | VALUE | obj | ) |

call-seq: obj.trust -> obj

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1078 of file object.c.

References rb_warn_deprecated_to_remove().

## ◆ rb_obj_untaint()

VALUE rb_obj_untaint | ( | VALUE | obj | ) |

call-seq: obj.untaint -> obj

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1035 of file object.c.

References rb_warn_deprecated_to_remove().

## ◆ rb_obj_untrust()

VALUE rb_obj_untrust | ( | VALUE | obj | ) |

call-seq: obj.untrust -> obj

Returns object. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1063 of file object.c.

References rb_warn_deprecated_to_remove().

## ◆ rb_obj_untrusted()

VALUE rb_obj_untrusted | ( | VALUE | obj | ) |

call-seq: obj.untrusted? -> false

Returns false. This method is deprecated and will be removed in Ruby 3.2.

Definition at line 1049 of file object.c.

References Qfalse, and rb_warn_deprecated_to_remove().

## ◆ rb_opts_exception_p()

int rb_opts_exception_p | ( | VALUE | opts,
|  | int | default_value
| ) |  |

Definition at line 3157 of file object.c.

References rb_bool_expected(), and rb_get_kwargs().

## ◆ rb_str_escape()

VALUE rb_str_escape | ( | VALUE | str | ) |

Definition at line 6135 of file string.c.

References CHAR_ESC_LEN, ENC_CODERANGE_7BIT, ENCODING_CODERANGE_SET, ENCODING_GET, int(), ISPRINT, MBCLEN_CHARFOUND_LEN, MBCLEN_CHARFOUND_P, rb_enc_asciicompat, rb_enc_from_index(), rb_enc_isascii, rb_enc_mbc_to_codepoint, rb_enc_mbminlen, rb_enc_precise_mbclen(), rb_enc_unicode_p(), rb_str_buf_cat_escaped_char(), rb_str_buf_new(), rb_usascii_encindex, RSTRING_PTR, ruby_escaped_char(), snprintf, str, and strlen().

Referenced by rb_inspect().

## ◆ rb_str_to_dbl()

double rb_str_to_dbl | ( | VALUE | str,
|  | int | badcheck
| ) |  |

Parses a string representation of a floating point number.

Parameters

  [in] | str | a `String` object representation of a floating number
  [in] | badcheck | raises an exception on parse error if badcheck is non-zero.

Returns
  the floating point number in the string on success, 0.0 on parse error and badcheck is zero.

Note
  it always fails to parse a hexadecimal representation like "0xAB.CDp+1" when badcheck is zero, even though it would success if badcheck was non-zero. This inconsistency is coming from a historical compatibility reason. [ruby-dev:40822]

Definition at line 3409 of file object.c.

References NULL, str, and TRUE.

## ◆ rb_String()

VALUE rb_String | ( | VALUE | val | ) |

Equivalent to `Kernel#String` in Ruby.

Converts val into `String` by trying `#to_str` at first and then trying `#to_s`.

Definition at line 3673 of file object.c.

References NIL_P, rb_check_string_type(), rb_convert_type_with_id(), and T_STRING.

## ◆ rb_to_float()

VALUE rb_to_float | ( | VALUE | val | ) |

Converts a `Numeric` object into `Float`.

Parameters

  [in] | val | a `Numeric` object

Exceptions

  TypeError | if val is not a `Numeric` or other conversion failures.

Definition at line 3559 of file object.c.

References T_FLOAT, and TRUE.

## ◆ rb_to_int()

VALUE rb_to_int | ( | VALUE | val | ) |

Converts val into `Integer`.

It calls #to_int method if necessary.

Parameters

  [in] | val | a Ruby object

Returns
  an `Integer` object

Exceptions

  TypeError | on failure

Definition at line 3051 of file object.c.

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

## Variable Documentation

## ◆ rb_cBasicObject

VALUE rb_cBasicObject

BasicObject class.

Definition at line 47 of file object.c.

Referenced by Init_class_hierarchy(), Init_GC(), Init_Ractor(), Init_VM(), Init_vm_eval(), and rb_class_superclass().

## ◆ rb_cClass

VALUE rb_cClass

Class class.

Definition at line 51 of file object.c.

Referenced by Init_class_hierarchy(), Init_eval(), rb_check_inheritable(), rb_class_boot(), and rb_include_class_new().

## ◆ rb_cFalseClass

VALUE rb_cFalseClass

FalseClass class.

Definition at line 55 of file object.c.

## ◆ rb_cModule

VALUE rb_cModule

Module class.

Definition at line 50 of file object.c.

Referenced by Init_class_hierarchy(), Init_eval(), Init_eval_method(), Init_load(), Init_Proc(), Init_vm_eval(), and rb_module_new().

## ◆ rb_cNilClass

VALUE rb_cNilClass

NilClass class.

Definition at line 53 of file object.c.

Referenced by Init_Complex(), and Init_Rational().

## ◆ rb_cObject

VALUE rb_cObject

Object class.

Definition at line 49 of file object.c.

Referenced by Init_Array(), Init_ast(), Init_Bignum(), Init_Binding(), Init_bubblebabble(), Init_class_hierarchy(), Init_Complex(), Init_Cont(), Init_cparse(), Init_date_core(), Init_dbm(), Init_Dir(), Init_Encoding(), Init_Exception(), Init_fiddle_closure(), Init_fiddle_function(), Init_fiddle_handle(), Init_fiddle_pinned(), Init_fiddle_pointer(), Init_File(), Init_GC(), Init_gdbm(), Init_generator(), Init_Hash(), Init_IO(), Init_ISeq(), Init_monitor(), Init_Numeric(), Init_objspace(), Init_ossl_asn1(), Init_ossl_bn(), Init_ossl_cipher(), Init_ossl_config(), Init_ossl_dh(), Init_ossl_dsa(), Init_ossl_ec(), Init_ossl_engine(), Init_ossl_hmac(), Init_ossl_ns_spki(), Init_ossl_ocsp(), Init_ossl_pkcs12(), Init_ossl_pkcs7(), Init_ossl_pkey(), Init_ossl_rsa(), Init_ossl_ssl(), Init_ossl_ssl_session(), Init_ossl_ts(), Init_ossl_x509attr(), Init_ossl_x509cert(), Init_ossl_x509crl(), Init_ossl_x509ext(), Init_ossl_x509name(), Init_ossl_x509req(), Init_ossl_x509revoked(), Init_ossl_x509store(), Init_parser(), Init_pathname(), Init_Proc(), Init_psych_emitter(), Init_psych_parser(), Init_psych_to_ruby(), Init_psych_yaml_tree(), Init_Ractor(), Init_Range(), Init_Rational(), Init_readline(), Init_Regexp(), Init_String(), Init_stringio(), Init_strscan(), Init_Thread(), Init_Time(), Init_top_self(), Init_VM(), Init_vm_backtrace(), Init_vm_trace(), Init_win32ole(), Init_win32ole_event(), Init_win32ole_method(), Init_win32ole_param(), Init_win32ole_record(), Init_win32ole_type(), Init_win32ole_typelib(), Init_win32ole_variable(), Init_win32ole_variant(), Init_zlib(), InitVM_console(), InitVM_digest(), InitVM_Enumerator(), InitVM_escape(), InitVM_process(), InitVM_Random(), InitVM_Struct(), InitVM_transcode(), rb_alias(), rb_catch(), rb_class_inherited(), rb_const_set(), rb_const_warn_if_deprecated(), rb_define_class(), rb_define_class_id(), rb_define_global_const(), rb_define_module(), rb_mod_const_of(), rb_path_to_class(), rb_set_class_path_string(), rb_uninterruptible(), rsock_init_addrinfo(), rsock_init_ancdata(), rsock_init_sockifaddr(), rsock_init_sockopt(), ruby_Init_Continuation_body(), and ruby_init_loadpath().

## ◆ rb_cTrueClass

VALUE rb_cTrueClass

TrueClass class.

Definition at line 54 of file object.c.

## ◆ rb_mKernel

VALUE rb_mKernel

Kernel module.

Definition at line 48 of file object.c.

Referenced by Init_eval(), Init_eval_method(), Init_GC(), Init_IO(), Init_Proc(), Init_vm_eval(), InitVM_Enumerator(), rb_define_global_function(), and rb_hash().