Ruby
3.4.0dev (2024-12-06 revision 892c46283a5ea4179500d951c9d4866c0051f27b)
|
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 |
#define RUBY_INTEGER_UNIFICATION 1 |
Exists here for backwards compatibility only. You can safely forget about it.
Generates a textual representation of the given object.
[in] | obj | Arbitrary ruby object. |
obj
. Object#to_s
that each subclasses want to override. 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.
[in] | val | An object to convert. |
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.
[in] | val | An object to convert. |
[in] | type | A value of enum ruby_value_type. |
[in] | name | Name to display on error (e.g. "Array"). |
[in] | mid | Conversion method (e.g. "to_ary"). |
rb_eTypeError | The mid does not generate type . |
RUBY_Qnil | No conversion defined. |
otherwise | An object of the specified type. |
This is complicated.
#to_f
method.[in] | val | An object to convert. |
RUBY_Qnil | Conversion from val to float is undefined. |
otherwise | Converted result. |
Identical to rb_check_to_integer(), except it uses #to_int
for conversion.
[in] | val | An object to convert. |
rb_eTypeError | #to_int does not return an integer. |
RUBY_Qnil | No conversion defined. |
otherwise | An instance of rb_cInteger. |
Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger.
[in] | val | An object to convert. |
[in] | mid | Conversion method (e.g. "to_ary"). |
rb_eTypeError | The mid does not generate an integer. |
RUBY_Qnil | No conversion defined. |
otherwise | An instance of rb_cInteger. |
Definition at line 3175 of file object.c.
Referenced by rb_io_extract_modeenc().
Returns the superclass of a class.
[in] | klass | An object of RClass. |
RUBY_Qfalse | klass has no super class. |
otherwise | Raw superclass of klass |
klass
could be a module. Or it could be rb_cBasicObject.Determines if the given two modules are relatives.
[in] | scion | Possible subclass. |
[in] | ascendant | Possible superclass. |
rb_eTypeError | ascendant is not a module. |
RUBY_Qtrue | scion inherits, or is equal to ascendant . |
RUBY_Qfalse | ascendant inherits scion . |
RUBY_Qnil | They are not relatives. |
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.
[in] | argc | Number of objects of argv . |
[in] | argv | Arguments passed to #initialize . |
[in] | klass | An instance of rb_cClass. |
rb_eTypeError | klass 's allocator is undefined. |
rb_eException | Any exceptions can happen inside. |
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().
Identical to rb_class_new_instance(), except you can specify how to handle the last element of the given array.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | klass | An instance of rb_cClass. |
[in] | kw_splat | Handling of keyword parameters:
|
rb_eTypeError | klass 's allocator is undefined. |
rb_eException | Any exceptions can happen inside. |
klass
. Definition at line 2122 of file object.c.
Referenced by rb_class_new_instance().
Identical to rb_class_new_instance(), except it passes the passed keywords if any to the #initialize
method.
[in] | argc | Number of objects of argv . |
[in] | argv | Arbitrary number of method arguments. |
[in] | klass | An instance of rb_cClass. |
rb_eTypeError | klass 's allocator is undefined. |
rb_eException | Any exceptions can happen inside. |
klass
. Object.new
. 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.
[in] | klass | An instance of rb_cClass. |
RUBY_Qfalse | No real class in klass ' ancestry tree. |
klass | klass itself is a real class. |
otherwise | Nearest 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().
Returns the superclass of klass
.
Queries the parent of the given class.
Equivalent to Class#superclass
in Ruby.
It skips modules.
[in] | klass | a Class object |
Qnil
if klass
does not have a parent class. Converts an object into another type.
Calls the specified conversion method if necessary.
[in] | val | An object to convert. |
[in] | type | A value of enum ruby_value_type. |
[in] | name | Name to display on error (e.g. "Array"). |
[in] | mid | Conversion method (e.g. "to_ary"). |
rb_eTypeError | Failed to convert. |
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.
[in] | str | A textual representation of a real number. |
[in] | mode | Conversion mode, as described above. |
rb_eArgError | Malformed str passed. |
Checks for equality of the passed objects, in terms of Object#eql?
.
[in] | lhs | Comparison left hand side. |
[in] | rhs | Comparison right hand side. |
non-zero | They are equal. |
0 | Otherwise. |
lhs.eql?(rhs)
so you cannot implement your class' #eql?
method using it. 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
.
[in] | lhs | Comparison LHS. |
[in] | rhs | Comparison RHS. |
RUBY_Qtrue | They are the same. |
RUBY_Qfalse | They 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().
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
.
[in] | val | An object to convert. |
rb_eArgError | Malformed val passed. |
rb_eTypeError | No conversion defined. |
Definition at line 3595 of file object.c.
Referenced by rb_str_format().
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).
[in] | obj | Arbitrary ruby object. |
obj
. Definition at line 680 of file object.c.
Referenced by rb_cmperr(), rb_p(), and rb_str_format().
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
.
[in] | val | An object to convert. |
rb_eArgError | Malformed val passed. |
rb_eTypeError | No conversion defined. |
Definition at line 3263 of file object.c.
Referenced by rb_str_format().
double rb_num2dbl | ( | VALUE | num | ) |
Converts an instance of rb_cNumeric into C's double
.
[in] | num | Something numeric. |
rb_eTypeError | num is not a numeric. |
double
. Allocates an instance of the given class.
[in] | klass | A class to instantiate. |
rb_eTypeError | klass is not a class. |
klass
. Definition at line 2093 of file object.c.
Referenced by rb_catch(), and rb_range_new().
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.
[in] | obj | Object in question. |
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().
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.
[in] | obj | Arbitrary ruby object. |
rb_eException | #initialize_copy can raise anything. |
obj
. Definition at line 521 of file object.c.
Referenced by rb_eval_string_wrap().
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.
[in] | obj | Arbitrary ruby object. |
rb_eException | #initialize_copy can raise anything. |
obj
. Definition at line 576 of file object.c.
Referenced by rb_io_path().
size_t rb_obj_embedded_size | ( | uint32_t | numiv | ) |
Internal header for Object.
Just calls rb_obj_freeze_inline() inside.
Does this make any sens to extension libraries?
[out] | obj | Object to freeze. |
obj
. Definition at line 1260 of file object.c.
Referenced by rb_ary_freeze(), rb_hash_freeze(), and rb_str_freeze().
Just calls RB_OBJ_FROZEN() inside.
Does this make any sens to extension libraries?
[in] | obj | Object in question. |
RUBY_Qtrue | Yes it is. |
RUBY_Qfalse | No it isn't. |
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.
[out] | obj | A Ruby object. |
Queries if the given object is a direct instance of the given class.
[in] | obj | Arbitrary ruby object. |
[in] | klass | An instance of rb_cModule. |
rb_eTypeError | klass is neither module nor class. |
RUBY_Qtrue | obj is an instance of klass . |
RUBY_Qfalse | Otherwise. |
Queries if the given object is an instance (of possibly descendants) of the given class.
[in] | obj | Arbitrary ruby object. |
[in] | klass | An instance of rb_cModule. |
rb_eTypeError | klass is neither module nor class. |
RUBY_Qtrue | obj is a klass . |
RUBY_Qfalse | Otherwise. |
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().
Make a hidden object visible again.
It is the caller's responsibility to pass the right klass
which obj
originally used to belong to.
[out] | obj | A Ruby object. |
[in] | klass | Class of obj . |
obj
. obj
was previously hidden. obj
's class is klass
. Fills common fields in the object.
[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. |
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.
[in] | str | A textual representation of a real number. |
[in] | mode | Conversion mode, as described in rb_cstr_to_dbl(). |
rb_eArgError | Malformed str passed. |
This is the logic behind Kernel#String
.
Arguments are converted by first trying #to_str
, then #to_s
.
[in] | val | An object to convert. |
rb_eTypeError | No conversion defined. |
Identical to rb_check_to_float(), except it raises on error.
[in] | val | An object to convert. |
rb_eTypeError | No conversion defined. |
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
[in] | val | An object to convert. |
rb_eTypeError | #to_int does not generate an integer. |
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().
|
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().
|
extern |
BasicObject
class.
Definition at line 64 of file object.c.
Referenced by Init_class_hierarchy(), and rb_class_superclass().
VALUE rb_cBasicObject |
BasicObject
class.
Definition at line 64 of file object.c.
Referenced by Init_class_hierarchy(), and rb_class_superclass().
|
extern |
Class
class.
Definition at line 68 of file object.c.
Referenced by rb_check_inheritable(), and rb_class_boot().
VALUE rb_cClass |
Class
class.
Definition at line 68 of file object.c.
Referenced by rb_check_inheritable(), and rb_class_boot().
|
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().
|
extern |
Encoding
class.
Definition at line 57 of file encoding.c.
|
extern |
Encoding
class.
Definition at line 57 of file encoding.c.
|
extern |
Enumerator
class.
Definition at line 163 of file enumerator.c.
Referenced by rb_enumeratorize_with_size_kw().
|
extern |
VALUE rb_cFalseClass |
|
extern |
File
class.
Definition at line 175 of file file.c.
Referenced by rb_file_open(), rb_file_open_str(), and rb_io_fdopen().
|
extern |
Float
class.
Definition at line 197 of file numeric.c.
Referenced by rb_class_of(), and rb_float_new_in_heap().
|
extern |
|
extern |
|
extern |
|
extern |
VALUE rb_cNilClass |
|
extern |
VALUE rb_cObject |
Documented in include/ruby/internal/globals.h.
Object
class.
|
extern |
Proc
class.
Definition at line 44 of file proc.c.
Referenced by rb_block_lambda(), and rb_block_proc().
|
extern |
Range
class.
Definition at line 31 of file range.c.
Referenced by rb_range_new(), and rb_range_values().
|
extern |
Rational
class.
Definition at line 53 of file rational.c.
Referenced by rb_Rational(), rb_rational_new(), and rb_rational_raw().
|
extern |
|
extern |
String
class.
Definition at line 78 of file string.c.
Referenced by rb_enc_str_new(), rb_enc_str_new_static(), rb_str_buf_new(), rb_str_new(), rb_str_new_static(), rb_str_plus(), rb_str_resurrect(), rb_str_times(), rb_sym_to_s(), rb_usascii_str_new(), rb_usascii_str_new_static(), rb_utf8_str_new(), and rb_utf8_str_new_static().
|
extern |
Struct
class.
Definition at line 33 of file struct.c.
Referenced by rb_struct_define(), and rb_struct_define_under().
|
extern |
Symbol
class.
Definition at line 79 of file string.c.
Referenced by rb_class_of(), and rb_str_intern().
|
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().
|
extern |
VALUE rb_cTrueClass |
|
extern |
VALUE rb_mKernel |
|
extern |
|
extern |
STDERR
constant.
Definition at line 201 of file io.c.
Referenced by rb_ractor_stderr(), and rb_ractor_stderr_set().
|
extern |
STDIN
constant.
Definition at line 201 of file io.c.
Referenced by rb_ractor_stdin(), and rb_ractor_stdin_set().
|
extern |
STDOUT
constant.
Definition at line 201 of file io.c.
Referenced by rb_ractor_stdout(), and rb_ractor_stdout_set().