14#include "ruby/internal/config.h"
25#include "internal/array.h"
26#include "internal/class.h"
27#include "internal/error.h"
28#include "internal/eval.h"
29#include "internal/inits.h"
30#include "internal/numeric.h"
31#include "internal/object.h"
32#include "internal/struct.h"
33#include "internal/string.h"
34#include "internal/symbol.h"
35#include "internal/variable.h"
61static VALUE rb_cNilClass_to_s;
62static VALUE rb_cTrueClass_to_s;
63static VALUE rb_cFalseClass_to_s;
69#define id_match idEqTilde
70#define id_inspect idInspect
71#define id_init_copy idInitialize_copy
72#define id_init_clone idInitialize_clone
73#define id_init_dup idInitialize_dup
74#define id_const_missing idConst_missing
77#define CLASS_OR_MODULE_P(obj) \
78 (!SPECIAL_CONST_P(obj) && \
79 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
87 RBASIC_CLEAR_CLASS(obj);
96 RBASIC_SET_CLASS(obj, klass);
105 RBASIC_SET_CLASS(obj, klass);
117#define case_equal rb_equal
126 if (obj1 == obj2)
return Qtrue;
127 result = rb_equal_opt(obj1, obj2);
128 if (UNDEF_P(result)) {
129 result = rb_funcall(obj1, id_eq, 1, obj2);
131 return RBOOL(
RTEST(result));
139 if (obj1 == obj2)
return TRUE;
140 result = rb_eql_opt(obj1, obj2);
141 if (UNDEF_P(result)) {
142 result = rb_funcall(obj1, id_eql, 1, obj2);
144 return RTEST(result);
150MJIT_FUNC_EXPORTED
VALUE
153 return RBOOL(obj1 == obj2);
162MJIT_FUNC_EXPORTED
VALUE
165 return RBOOL(!
RTEST(obj));
172MJIT_FUNC_EXPORTED
VALUE
175 VALUE result = rb_funcall(obj1, id_eq, 1, obj2);
176 return rb_obj_not(result);
213rb_obj_singleton_class(
VALUE obj)
219MJIT_FUNC_EXPORTED
void
225 rb_shape_t * src_shape = rb_shape_get_shape(obj);
227 if (rb_shape_id(src_shape) == OBJ_TOO_COMPLEX_SHAPE_ID) {
228 struct rb_id_table * table = rb_id_table_create(rb_id_table_size(ROBJECT_IV_HASH(obj)));
230 rb_ivar_foreach(obj, rb_obj_evacuate_ivs_to_hash_table, (st_data_t)table);
231 rb_shape_set_too_complex(dest);
238 uint32_t src_num_ivs = RBASIC_IV_COUNT(obj);
239 rb_shape_t * shape_to_set_on_dest = src_shape;
248 if (rb_shape_frozen_shape_p(src_shape)) {
249 shape_to_set_on_dest = rb_shape_get_parent(src_shape);
252 src_buf = ROBJECT_IVPTR(obj);
253 dest_buf = ROBJECT_IVPTR(dest);
255 rb_shape_t * initial_shape = rb_shape_get_shape(dest);
257 if (initial_shape->size_pool_index != src_shape->size_pool_index) {
258 RUBY_ASSERT(initial_shape->type == SHAPE_T_OBJECT);
260 shape_to_set_on_dest = rb_shape_rebuild_shape(initial_shape, src_shape);
263 RUBY_ASSERT(src_num_ivs <= shape_to_set_on_dest->capacity);
264 if (initial_shape->capacity < shape_to_set_on_dest->capacity) {
265 rb_ensure_iv_list_size(dest, initial_shape->capacity, shape_to_set_on_dest->capacity);
266 dest_buf = ROBJECT_IVPTR(dest);
272 for (uint32_t i = 0; i < src_num_ivs; i++) {
276 rb_shape_set_shape(dest, shape_to_set_on_dest);
288 rb_copy_wb_protected_attribute(dest, obj);
290 rb_gc_copy_finalizer(dest, obj);
293 rb_obj_copy_ivar(dest, obj);
299PUREFUNC(
static inline int special_object_p(
VALUE obj));
301special_object_p(
VALUE obj)
318obj_freeze_opt(
VALUE freeze)
335 VALUE kwfreeze = obj_freeze_opt(freeze);
336 if (!special_object_p(obj))
337 return mutable_obj_clone(obj, kwfreeze);
338 return immutable_obj_clone(obj, kwfreeze);
343rb_immutable_obj_clone(
int argc,
VALUE *argv,
VALUE obj)
345 VALUE kwfreeze = rb_get_freeze_opt(argc, argv);
346 return immutable_obj_clone(obj, kwfreeze);
350rb_get_freeze_opt(
int argc,
VALUE *argv)
352 static ID keyword_ids[1];
356 if (!keyword_ids[0]) {
359 rb_scan_args(argc, argv,
"0:", &opt);
362 if (!UNDEF_P(kwfreeze))
363 kwfreeze = obj_freeze_opt(kwfreeze);
380 VALUE clone, singleton;
385 singleton = rb_singleton_class_clone_and_attach(obj, clone);
386 RBASIC_SET_CLASS(clone, singleton);
391 init_copy(clone, obj);
395 rb_funcall(clone, id_init_clone, 1, obj);
397 if (RB_OBJ_FROZEN(obj)) {
398 rb_shape_transition_shape_frozen(clone);
403 static VALUE freeze_true_hash;
404 if (!freeze_true_hash) {
405 freeze_true_hash = rb_hash_new();
406 rb_gc_register_mark_object(freeze_true_hash);
407 rb_hash_aset(freeze_true_hash,
ID2SYM(idFreeze),
Qtrue);
412 argv[1] = freeze_true_hash;
415 rb_shape_transition_shape_frozen(clone);
420 static VALUE freeze_false_hash;
421 if (!freeze_false_hash) {
422 freeze_false_hash = rb_hash_new();
423 rb_gc_register_mark_object(freeze_false_hash);
424 rb_hash_aset(freeze_false_hash,
ID2SYM(idFreeze),
Qfalse);
429 argv[1] = freeze_false_hash;
434 rb_bug(
"invalid kwfreeze passed to mutable_obj_clone");
443 if (special_object_p(obj))
return obj;
444 return mutable_obj_clone(obj,
Qnil);
491 if (special_object_p(obj)) {
496 rb_funcall(dup, id_init_dup, 1, obj);
513rb_obj_itself(
VALUE obj)
538 if (obj == orig)
return obj;
555 rb_funcall(obj, id_init_copy, 1, orig);
570 if (rb_scan_args(argc, argv,
"1:", &orig, &opts) < argc) {
572 rb_get_freeze_opt(1, &opts);
574 rb_funcall(obj, id_init_copy, 1, orig);
594 str =
rb_sprintf(
"#<%"PRIsVALUE
":%p>", cname, (
void*)obj);
605 if (enc == NULL) enc = rb_default_external_encoding();
606 if (!rb_enc_asciicompat(enc)) {
608 return rb_str_escape(str);
612 return rb_str_escape(str);
617inspect_i(st_data_t k, st_data_t v, st_data_t a)
624 if (
CLASS_OF(value) == 0)
return ST_CONTINUE;
626 if (RSTRING_PTR(str)[0] ==
'-') {
627 RSTRING_PTR(str)[0] =
'#';
649 RSTRING_PTR(str)[0] =
'#';
682rb_obj_inspect(
VALUE obj)
688 str =
rb_sprintf(
"-<%"PRIsVALUE
":%p", c, (
void*)obj);
697class_or_module_required(
VALUE c)
699 switch (OBJ_BUILTIN_TYPE(c)) {
733 c = class_or_module_required(c);
745 size_t c_depth = RCLASS_SUPERCLASS_DEPTH(c);
746 size_t cl_depth = RCLASS_SUPERCLASS_DEPTH(cl);
747 VALUE *classes = RCLASS_SUPERCLASSES(cl);
751 if (cl_depth <= c_depth)
755 return RBOOL(classes[c_depth] == c);
795 if (cl == c)
return Qtrue;
800 if (LIKELY(RB_TYPE_P(c,
T_CLASS))) {
802 return class_search_class_ancestor(cl, c);
807 VALUE includer = RCLASS_INCLUDER(c);
808 if (cl == includer)
return Qtrue;
814 if (RB_TYPE_P(includer,
T_CLASS) && class_search_class_ancestor(cl, includer))
819 return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
823 return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
836 if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
847 cl = class_or_module_required(cl);
848 c = class_or_module_required(c);
849 return class_search_ancestor(cl, RCLASS_ORIGIN(c));
880#define rb_obj_class_inherited rb_obj_dummy1
903#define rb_obj_mod_method_added rb_obj_dummy1
930#define rb_obj_mod_method_removed rb_obj_dummy1
957#define rb_obj_mod_method_undefined rb_obj_dummy1
984#define rb_obj_singleton_method_added rb_obj_dummy1
1013#define rb_obj_singleton_method_removed rb_obj_dummy1
1038#define rb_obj_singleton_method_undefined rb_obj_dummy1
1060#define rb_obj_mod_const_added rb_obj_dummy1
1080#define rb_obj_mod_extended rb_obj_dummy1
1103#define rb_obj_mod_included rb_obj_dummy1
1123#define rb_obj_mod_prepended rb_obj_dummy1
1133#define rb_obj_initialize rb_obj_dummy0
1148 return rb_obj_dummy();
1154 return rb_obj_dummy();
1187 rb_bug(
"special consts should be frozen.");
1213MJIT_FUNC_EXPORTED
VALUE
1214rb_nil_to_s(
VALUE obj)
1216 return rb_cNilClass_to_s;
1250 return rb_hash_new();
1261nil_inspect(
VALUE obj)
1298MJIT_FUNC_EXPORTED
VALUE
1299rb_true_to_s(
VALUE obj)
1301 return rb_cTrueClass_to_s;
1316 return RBOOL(
RTEST(obj2));
1354 return rb_obj_not(obj2);
1375MJIT_FUNC_EXPORTED
VALUE
1376rb_false_to_s(
VALUE obj)
1378 return rb_cFalseClass_to_s;
1407#define false_or true_and
1420#define false_xor true_and
1446MJIT_FUNC_EXPORTED
VALUE
1463 VALUE result = rb_funcall(obj1, id_match, 1, obj2);
1464 return rb_obj_not(result);
1531MJIT_FUNC_EXPORTED
VALUE
1532rb_mod_to_s(
VALUE klass)
1535 VALUE refined_class, defined_at;
1541 if (CLASS_OR_MODULE_P(v)) {
1551 refined_class = rb_refinement_module_get_refined_class(klass);
1552 if (!
NIL_P(refined_class)) {
1557 CONST_ID(id_defined_at,
"__defined_at__");
1576rb_mod_freeze(
VALUE mod)
1612 if (mod == arg)
return Qtrue;
1616 size_t mod_depth = RCLASS_SUPERCLASS_DEPTH(mod);
1617 size_t arg_depth = RCLASS_SUPERCLASS_DEPTH(arg);
1618 if (arg_depth < mod_depth) {
1620 return RCLASS_SUPERCLASSES(mod)[arg_depth] == arg ?
1624 else if (arg_depth > mod_depth) {
1626 return RCLASS_SUPERCLASSES(arg)[mod_depth] == mod ?
1636 if (!CLASS_OR_MODULE_P(arg) && !RB_TYPE_P(arg,
T_ICLASS)) {
1639 if (class_search_ancestor(mod, RCLASS_ORIGIN(arg))) {
1643 if (class_search_ancestor(arg, mod)) {
1666 if (mod == arg)
return Qfalse;
1686 if (!CLASS_OR_MODULE_P(arg)) {
1709 if (mod == arg)
return Qfalse;
1710 return rb_mod_ge(mod, arg);
1730 if (mod == arg)
return INT2FIX(0);
1731 if (!CLASS_OR_MODULE_P(arg)) {
1743static VALUE rb_mod_initialize_exec(
VALUE module);
1772rb_mod_initialize(
VALUE module)
1774 return rb_mod_initialize_exec(module);
1778rb_mod_initialize_exec(
VALUE module)
1788rb_mod_initialize_clone(
int argc,
VALUE* argv,
VALUE clone)
1790 VALUE ret, orig, opts;
1791 rb_scan_args(argc, argv,
"1:", &orig, &opts);
1829rb_class_initialize(
int argc,
VALUE *argv,
VALUE klass)
1836 if (rb_check_arity(argc, 0, 1) == 0) {
1846 RCLASS_SET_SUPER(klass, super);
1847 rb_make_metaclass(klass,
RBASIC(super)->klass);
1849 rb_mod_initialize_exec(klass);
1856rb_undefined_alloc(
VALUE klass)
1888rb_class_alloc_m(
VALUE klass)
1895 return class_call_alloc_func(allocator, klass);
1899rb_class_alloc(
VALUE klass)
1902 return class_call_alloc_func(allocator, klass);
1906class_get_alloc_func(
VALUE klass)
1918 rb_undefined_alloc(klass);
1930 obj = (*allocator)(klass);
1942 return rb_class_alloc(klass);
1961 obj = rb_class_alloc(klass);
1973 obj = rb_class_alloc(klass);
1974 rb_obj_call_init_kw(obj, argc, argv, kw_splat);
2006 super = RCLASS_SUPERCLASSES(klass)[RCLASS_SUPERCLASS_DEPTH(klass) - 1];
2015 return RCLASS(klass)->super;
2018static const char bad_instance_name[] =
"`%1$s' is not allowed as an instance variable name";
2019static const char bad_class_name[] =
"`%1$s' is not allowed as a class variable name";
2020static const char bad_const_name[] =
"wrong constant name %1$s";
2021static const char bad_attr_name[] =
"invalid attribute name `%1$s'";
2022#define wrong_constant_name bad_const_name
2025#define id_for_var(obj, name, type) id_for_setter(obj, name, type, bad_##type##_name)
2027#define id_for_setter(obj, name, type, message) \
2028 check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))
2031 int (*valid_id_p)(
ID),
int (*valid_name_p)(
VALUE),
2032 const char *message,
size_t message_len)
2035 VALUE name = *pname;
2037 if (
id ? !valid_id_p(
id) : !valid_name_p(name)) {
2038 rb_name_err_raise_str(rb_fstring_new(message, message_len),
2045rb_is_attr_name(
VALUE name)
2047 return rb_is_local_name(name) || rb_is_const_name(name);
2059 ID id = id_for_var(obj, name, attr);
2079rb_mod_attr_reader(
int argc,
VALUE *argv,
VALUE klass)
2084 for (i=0; i<argc; i++) {
2085 ID id = id_for_attr(klass, argv[i]);
2086 rb_attr(klass,
id, TRUE, FALSE, TRUE);
2087 rb_ary_push(names,
ID2SYM(
id));
2097rb_mod_attr(
int argc,
VALUE *argv,
VALUE klass)
2099 if (argc == 2 && (argv[1] ==
Qtrue || argv[1] ==
Qfalse)) {
2100 ID id = id_for_attr(klass, argv[0]);
2101 VALUE names = rb_ary_new();
2105 rb_ary_push(names,
ID2SYM(
id));
2109 return rb_mod_attr_reader(argc, argv, klass);
2124rb_mod_attr_writer(
int argc,
VALUE *argv,
VALUE klass)
2129 for (i=0; i<argc; i++) {
2130 ID id = id_for_attr(klass, argv[i]);
2131 rb_attr(klass,
id, FALSE, TRUE, TRUE);
2156rb_mod_attr_accessor(
int argc,
VALUE *argv,
VALUE klass)
2161 for (i=0; i<argc; i++) {
2162 ID id = id_for_attr(klass, argv[i]);
2164 rb_attr(klass,
id, TRUE, TRUE, TRUE);
2165 rb_ary_push(names,
ID2SYM(
id));
2212rb_mod_const_get(
int argc,
VALUE *argv,
VALUE mod)
2216 const char *pbeg, *p, *path, *pend;
2219 rb_check_arity(argc, 1, 2);
2221 recur = (argc == 1) ?
Qtrue : argv[1];
2224 if (!rb_is_const_sym(name))
goto wrong_name;
2226 if (!
id)
return rb_const_missing(mod, name);
2231 enc = rb_enc_get(name);
2233 if (!rb_enc_asciicompat(enc)) {
2238 pend = path + RSTRING_LEN(name);
2240 if (p >= pend || !*p) {
2244 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2254 while (p < pend && *p !=
':') p++;
2256 if (pbeg == p)
goto wrong_name;
2261 if (p < pend && p[0] ==
':') {
2262 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2275 if (!rb_is_const_name(part)) {
2279 else if (!rb_method_basic_definition_p(
CLASS_OF(mod), id_const_missing)) {
2281 mod = rb_const_missing(mod, part);
2285 rb_mod_const_missing(mod, part);
2293 mod = rb_const_get_0(mod,
id, beglen > 0 || !
RTEST(recur),
RTEST(recur), FALSE);
2295 if (!
RTEST(recur)) {
2298 else if (beglen == 0) {
2310 rb_name_err_raise(wrong_constant_name, mod, name);
2336 ID id = id_for_var(mod, name,
const);
2385rb_mod_const_defined(
int argc,
VALUE *argv,
VALUE mod)
2389 const char *pbeg, *p, *path, *pend;
2392 rb_check_arity(argc, 1, 2);
2394 recur = (argc == 1) ?
Qtrue : argv[1];
2397 if (!rb_is_const_sym(name))
goto wrong_name;
2404 enc = rb_enc_get(name);
2406 if (!rb_enc_asciicompat(enc)) {
2411 pend = path + RSTRING_LEN(name);
2413 if (p >= pend || !*p) {
2417 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2427 while (p < pend && *p !=
':') p++;
2429 if (pbeg == p)
goto wrong_name;
2434 if (p < pend && p[0] ==
':') {
2435 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2443 if (!rb_is_const_name(part)) {
2457 mod = rb_const_search(mod,
id, beglen > 0 || !
RTEST(recur),
RTEST(recur), FALSE);
2458 if (UNDEF_P(mod))
return Qfalse;
2460 if (!
RTEST(recur)) {
2463 if (p == pend)
return Qtrue;
2466 else if (beglen == 0) {
2469 if (p == pend)
return Qtrue;
2475 if (p == pend)
return Qtrue;
2480 if (p < pend && !RB_TYPE_P(mod,
T_MODULE) && !RB_TYPE_P(mod,
T_CLASS)) {
2489 rb_name_err_raise(wrong_constant_name, mod, name);
2545rb_mod_const_source_location(
int argc,
VALUE *argv,
VALUE mod)
2549 const char *pbeg, *p, *path, *pend;
2552 rb_check_arity(argc, 1, 2);
2554 recur = (argc == 1) ?
Qtrue : argv[1];
2557 if (!rb_is_const_sym(name))
goto wrong_name;
2559 if (!
id)
return Qnil;
2560 return RTEST(recur) ? rb_const_source_location(mod,
id) : rb_const_source_location_at(mod, id);
2564 enc = rb_enc_get(name);
2566 if (!rb_enc_asciicompat(enc)) {
2571 pend = path + RSTRING_LEN(name);
2573 if (p >= pend || !*p) {
2577 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2587 while (p < pend && *p !=
':') p++;
2589 if (pbeg == p)
goto wrong_name;
2594 if (p < pend && p[0] ==
':') {
2595 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2603 if (!rb_is_const_name(part)) {
2629 loc = rb_const_source_location(mod,
id);
2632 loc = rb_const_source_location_at(mod,
id);
2642 rb_name_err_raise(wrong_constant_name, mod, name);
2671 ID id = id_for_var(obj, iv, instance);
2705 ID id = id_for_var(obj, iv, instance);
2733 ID id = id_for_var(obj, iv, instance);
2760 ID id = id_for_var(obj, iv,
class);
2763 rb_name_err_raise(
"uninitialized class variable %1$s in %2$s",
2792 ID id = id_for_var(obj, iv,
class);
2817 ID id = id_for_var(obj, iv,
class);
2839rb_mod_singleton_p(
VALUE klass)
2845static const struct conv_method_tbl {
2846 const char method[6];
2848} conv_method_names[] = {
2849#define M(n) {#n, (unsigned short)idTo_##n}
2864#define IMPLICIT_CONVERSIONS 7
2867conv_method_index(
const char *method)
2869 static const char prefix[] =
"to_";
2871 if (strncmp(prefix, method,
sizeof(prefix)-1) == 0) {
2872 const char *
const meth = &method[
sizeof(prefix)-1];
2874 for (i=0; i < numberof(conv_method_names); i++) {
2875 if (conv_method_names[i].method[0] == meth[0] &&
2876 strcmp(conv_method_names[i].method, meth) == 0) {
2881 return numberof(conv_method_names);
2885convert_type_with_id(
VALUE val,
const char *tname,
ID method,
int raise,
int index)
2891 ((index < 0 ? conv_method_index(
rb_id2name(method)) : index)
2892 < IMPLICIT_CONVERSIONS) ?
2893 "no implicit conversion of" :
"can't convert";
2894 const char *cname =
NIL_P(val) ?
"nil" :
2895 val ==
Qtrue ?
"true" :
2896 val ==
Qfalse ?
"false" :
2910convert_type(
VALUE val,
const char *tname,
const char *method,
int raise)
2912 int i = conv_method_index(method);
2913 ID m = i < numberof(conv_method_names) ?
2914 conv_method_names[i].id : rb_intern(method);
2915 return convert_type_with_id(val, tname, m, raise, i);
2919NORETURN(
static void conversion_mismatch(
VALUE,
const char *,
const char *,
VALUE));
2921conversion_mismatch(
VALUE val,
const char *tname,
const char *method,
VALUE result)
2925 "can't convert %"PRIsVALUE
" to %s (%"PRIsVALUE
"#%s gives %"PRIsVALUE
")",
2935 v = convert_type(val, tname, method, TRUE);
2937 conversion_mismatch(val, tname, method, v);
2944rb_convert_type_with_id(
VALUE val,
int type,
const char *tname,
ID method)
2949 v = convert_type_with_id(val, tname, method, TRUE, -1);
2951 conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v);
2963 v = convert_type(val, tname, method, FALSE);
2966 conversion_mismatch(val, tname, method, v);
2972MJIT_FUNC_EXPORTED
VALUE
2973rb_check_convert_type_with_id(
VALUE val,
int type,
const char *tname,
ID method)
2979 v = convert_type_with_id(val, tname, method, FALSE, -1);
2982 conversion_mismatch(val, tname, RSTRING_PTR(rb_id2str(method)), v);
2987#define try_to_int(val, mid, raise) \
2988 convert_type_with_id(val, "Integer", mid, raise, -1)
2990ALWAYS_INLINE(
static VALUE rb_to_integer_with_id_exception(
VALUE val,
const char *method,
ID mid,
int raise));
2993rb_to_integer_with_id_exception(
VALUE val,
const char *method,
ID mid,
int raise)
2998 v = try_to_int(val, mid, raise);
3001 conversion_mismatch(val,
"Integer", method, v);
3005#define rb_to_integer(val, method, mid) \
3006 rb_to_integer_with_id_exception(val, method, mid, TRUE)
3014 v = convert_type(val,
"Integer", method, FALSE);
3024 return rb_to_integer(val,
"to_int", idTo_int);
3031 val = try_to_int(val, idTo_int, FALSE);
3037rb_check_to_i(
VALUE val)
3040 val = try_to_int(val, idTo_i, FALSE);
3046rb_convert_to_integer(
VALUE val,
int base,
int raise_exception)
3056 else if (! raise_exception) {
3063 if (RB_FLOAT_TYPE_P(val)) {
3065 if (!raise_exception && !isfinite(f))
return Qnil;
3067 return rb_dbl2big(f);
3072 else if (RB_TYPE_P(val,
T_STRING)) {
3073 return rb_str_convert_to_inum(val, base, TRUE, raise_exception);
3075 else if (
NIL_P(val)) {
3076 if (!raise_exception)
return Qnil;
3084 return rb_str_convert_to_inum(tmp, base, TRUE, raise_exception);
3087 if (!raise_exception) {
3088 VALUE result = rb_protect(rb_check_to_i, val, NULL);
3093 return rb_to_integer(val,
"to_i", idTo_i);
3099 return rb_convert_to_integer(val, 0, TRUE);
3103rb_check_integer_type(
VALUE val)
3105 return rb_to_integer_with_id_exception(val,
"to_int", idTo_int, FALSE);
3109rb_bool_expected(
VALUE obj,
const char *flagname,
int raise)
3117 static const char message[] =
"expected true or false as %s: %+"PRIsVALUE;
3128rb_opts_exception_p(
VALUE opts,
int default_value)
3130 static const ID kwds[1] = {idException};
3133 return rb_bool_expected(exception,
"exception", TRUE);
3134 return default_value;
3137#define opts_exception_p(opts) rb_opts_exception_p((opts), TRUE)
3228rb_f_integer(
int argc,
VALUE *argv,
VALUE obj)
3236 if (!
NIL_P(vbase)) {
3241 VALUE hash = rb_check_hash_type(argv[argc-1]);
3248 rb_check_arity(argc, 1, 2);
3251 return rb_convert_to_integer(arg, base, opts_exception_p(opts));
3255rb_cstr_to_dbl_raise(
const char *p,
int badcheck,
int raise,
int *error)
3260 const char *ellipsis =
"";
3262 enum {max_width = 20};
3263#define OutOfRange() ((end - p > max_width) ? \
3264 (w = max_width, ellipsis = "...") : \
3265 (w = (int)(end - p), ellipsis = ""))
3271 if (!badcheck && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3276 if (errno == ERANGE) {
3278 rb_warning(
"Float %.*s%s out of range", w, p, ellipsis);
3288 char buf[DBL_DIG * 4 + 10];
3290 char *
const init_e = buf + DBL_DIG * 4;
3293 int dot_seen = FALSE;
3295 switch (*p) {
case '+':
case '-': prev = *n++ = *p++;}
3298 while (*++p ==
'0');
3300 while (p < end && n < e) prev = *n++ = *p++;
3305 if (badcheck)
goto bad;
3310 if (e == init_e && (prev ==
'e' || prev ==
'E' || prev ==
'p' || prev ==
'P')) {
3311 e = buf +
sizeof(buf) - 1;
3313 switch (*p) {
case '+':
case '-': prev = *n++ = *p++;}
3316 while (*++p ==
'0');
3323 if (badcheck)
goto bad;
3327 else if (prev ==
'.' ? dot_seen++ : !
ISDIGIT(prev)) {
3328 if (badcheck)
goto bad;
3331 if (n < e) *n++ = prev;
3336 if (!badcheck && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3341 if (errno == ERANGE) {
3343 rb_warning(
"Float %.*s%s out of range", w, p, ellipsis);
3347 if (!end || p == end)
goto bad;
3348 while (*end &&
ISSPACE(*end)) end++;
3352 if (errno == ERANGE) {
3365 if (error) *error = 1;
3373 return rb_cstr_to_dbl_raise(p, badcheck, TRUE, NULL);
3377rb_str_to_dbl_raise(
VALUE str,
int badcheck,
int raise,
int *error)
3385 s = RSTRING_PTR(str);
3386 len = RSTRING_LEN(str);
3388 if (badcheck && memchr(s,
'\0', len)) {
3392 if (error) *error = 1;
3397 char *p =
ALLOCV(v, (
size_t)len + 1);
3403 ret = rb_cstr_to_dbl_raise(s, badcheck, raise, error);
3414 return rb_str_to_dbl_raise(str, badcheck, TRUE, NULL);
3418#define fix2dbl_without_to_f(x) (double)FIX2LONG(x)
3419#define big2dbl_without_to_f(x) rb_big2dbl(x)
3420#define int2dbl_without_to_f(x) \
3421 (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : big2dbl_without_to_f(x))
3422#define num2dbl_without_to_f(x) \
3423 (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : \
3424 RB_BIGNUM_TYPE_P(x) ? big2dbl_without_to_f(x) : \
3425 (Check_Type(x, T_FLOAT), RFLOAT_VALUE(x)))
3427rat2dbl_without_to_f(
VALUE x)
3431 return num2dbl_without_to_f(num) / num2dbl_without_to_f(den);
3434#define special_const_to_float(val, pre, post) \
3437 rb_raise_static(rb_eTypeError, pre "nil" post); \
3439 rb_raise_static(rb_eTypeError, pre "true" post); \
3441 rb_raise_static(rb_eTypeError, pre "false" post); \
3446conversion_to_float(
VALUE val)
3448 special_const_to_float(val,
"can't convert ",
" into Float");
3452implicit_conversion_to_float(
VALUE val)
3454 special_const_to_float(val,
"no implicit conversion to float from ",
"");
3458to_float(
VALUE *valp,
int raise_exception)
3463 *valp =
DBL2NUM(fix2dbl_without_to_f(val));
3469 else if (raise_exception) {
3470 conversion_to_float(val);
3479 *valp =
DBL2NUM(big2dbl_without_to_f(val));
3482 *valp =
DBL2NUM(rat2dbl_without_to_f(val));
3492convert_type_to_float_protected(
VALUE val)
3494 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3498rb_convert_to_float(
VALUE val,
int raise_exception)
3500 switch (to_float(&val, raise_exception)) {
3504 if (!raise_exception) {
3506 double x = rb_str_to_dbl_raise(val, TRUE, raise_exception, &e);
3515 if (!raise_exception) {
3517 VALUE result = rb_protect(convert_type_to_float_protected, val, &state);
3522 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3530 return rb_convert_to_float(val, TRUE);
3536 return rb_convert_to_float(arg, TRUE);
3542 int exception = rb_bool_expected(opts,
"exception", TRUE);
3543 return rb_convert_to_float(arg, exception);
3547numeric_to_float(
VALUE val)
3553 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3559 switch (to_float(&val, TRUE)) {
3563 return numeric_to_float(val);
3569 if (RB_FLOAT_TYPE_P(val))
return val;
3573 return rb_check_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3577basic_to_f_p(
VALUE klass)
3579 return rb_method_basic_definition_p(klass, id_to_f);
3584rb_num_to_dbl(
VALUE val)
3589 return fix2dbl_without_to_f(val);
3592 return rb_float_flonum_value(val);
3595 conversion_to_float(val);
3601 return rb_float_noflonum_value(val);
3604 return big2dbl_without_to_f(val);
3608 return rat2dbl_without_to_f(val);
3614 val = numeric_to_float(val);
3623 return fix2dbl_without_to_f(val);
3626 return rb_float_flonum_value(val);
3629 implicit_conversion_to_float(val);
3635 return rb_float_noflonum_value(val);
3637 return big2dbl_without_to_f(val);
3639 return rat2dbl_without_to_f(val);
3646 val = rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3655 tmp = rb_convert_type_with_id(val,
T_STRING,
"String", idTo_s);
3685 VALUE tmp = rb_check_array_type(val);
3688 tmp = rb_check_to_array(val);
3730 if (
NIL_P(val))
return rb_hash_new();
3731 tmp = rb_check_hash_type(val);
3734 return rb_hash_new();
3777dig_basic_p(
VALUE obj,
struct dig_method *cache)
3779 VALUE klass = RBASIC_CLASS(obj);
3780 if (klass != cache->klass) {
3781 cache->klass = klass;
3782 cache->basic = rb_method_basic_definition_p(klass, id_dig);
3784 return cache->basic;
3788no_dig_method(
int found,
VALUE recv,
ID mid,
int argc,
const VALUE *argv,
VALUE data)
3800 struct dig_method hash = {
Qnil}, ary = {
Qnil}, strt = {
Qnil};
3802 for (; argc > 0; ++argv, --argc) {
3803 if (
NIL_P(obj))
return notfound;
3807 if (dig_basic_p(obj, &hash)) {
3808 obj = rb_hash_aref(obj, *argv);
3813 if (dig_basic_p(obj, &ary)) {
3814 obj = rb_ary_at(obj, *argv);
3819 if (dig_basic_p(obj, &strt)) {
3820 obj = rb_struct_lookup(obj, *argv);
3828 return rb_check_funcall_with_hook_kw(obj, id_dig, argc, argv,
4329 rb_cNilClass_to_s = rb_fstring_enc_lit(
"", rb_usascii_encoding());
4330 rb_gc_register_mark_object(rb_cNilClass_to_s);
4378 rb_class_undefined_instance_methods, 0);
4388 rb_mod_const_missing, 1);
4414 rb_cTrueClass_to_s = rb_fstring_enc_lit(
"true", rb_usascii_encoding());
4415 rb_gc_register_mark_object(rb_cTrueClass_to_s);
4426 rb_cFalseClass_to_s = rb_fstring_enc_lit(
"false", rb_usascii_encoding());
4427 rb_gc_register_mark_object(rb_cFalseClass_to_s);
4438#include "kernel.rbinc"
4439#include "nilclass.rbinc"
4444 id_dig = rb_intern_const(
"dig");
#define RUBY_ASSERT(expr)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
#define rb_define_global_function(mid, func, arity)
Defines rb_mKernel #mid.
VALUE rb_class_protected_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are protected only.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
VALUE rb_class_subclasses(VALUE klass)
Queries the class's direct descendants.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
void Init_class_hierarchy(void)
Internal header aggregating init functions.
VALUE rb_class_attached_object(VALUE klass)
Returns the attached object for a singleton class.
VALUE rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
Identical to rb_class_instance_methods(), except it returns names of singleton methods instead of ins...
VALUE rb_class_instance_methods(int argc, const VALUE *argv, VALUE mod)
Generates an array of symbols, which are the list of method names defined in the passed class.
void rb_check_inheritable(VALUE super)
Asserts that the given class can derive a child class.
VALUE rb_class_public_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are public only.
VALUE rb_define_module(const char *name)
Defines a top-level module.
void rb_singleton_class_attached(VALUE klass, VALUE obj)
Attaches a singleton class to its corresponding object.
VALUE rb_mod_included_modules(VALUE mod)
Queries the list of included modules.
VALUE rb_mod_ancestors(VALUE mod)
Queries the module's ancestors.
VALUE rb_class_inherited(VALUE super, VALUE klass)
Calls Class::inherited.
VALUE rb_mod_include_p(VALUE mod, VALUE mod2)
Queries if the passed module is included by the module.
VALUE rb_class_private_instance_methods(int argc, const VALUE *argv, VALUE mod)
Identical to rb_class_instance_methods(), except it returns names of methods that are private only.
VALUE rb_mod_init_copy(VALUE clone, VALUE orig)
The comment that comes with this function says :nodoc:.
void rb_define_alias(VALUE klass, const char *name1, const char *name2)
Defines an alias of a method.
VALUE rb_extract_keywords(VALUE *orighash)
Splits a hash into two.
void rb_undef_method(VALUE klass, const char *name)
Defines an undef of a method.
int rb_block_given_p(void)
Determines if the current method is given a block.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define T_COMPLEX
Old name of RUBY_T_COMPLEX.
#define TYPE(_)
Old name of rb_type.
#define FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define FL_EXIVAR
Old name of RUBY_FL_EXIVAR.
#define ALLOCV
Old name of RB_ALLOCV.
#define ISSPACE
Old name of rb_isspace.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define T_MASK
Old name of RUBY_T_MASK.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
#define rb_str_cat2
Old name of rb_str_cat_cstr.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define ID2SYM
Old name of RB_ID2SYM.
#define T_BIGNUM
Old name of RUBY_T_BIGNUM.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define T_STRUCT
Old name of RUBY_T_STRUCT.
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define T_DATA
Old name of RUBY_T_DATA.
#define CLASS_OF
Old name of rb_class_of.
#define T_NONE
Old name of RUBY_T_NONE.
#define FIXABLE
Old name of RB_FIXABLE.
#define LONG2FIX
Old name of RB_INT2FIX.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define ISDIGIT
Old name of rb_isdigit.
#define T_RATIONAL
Old name of RUBY_T_RATIONAL.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
#define T_HASH
Old name of RUBY_T_HASH.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define rb_usascii_str_new2
Old name of rb_usascii_str_new_cstr.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define DBL2NUM
Old name of rb_float_new.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define FL_TEST
Old name of RB_FL_TEST.
#define FL_FREEZE
Old name of RUBY_FL_FREEZE.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define CONST_ID
Old name of RUBY_CONST_ID.
#define rb_ary_new2
Old name of rb_ary_new_capa.
#define ALLOCV_END
Old name of RB_ALLOCV_END.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_category_warning(rb_warning_category_t category, const char *fmt,...)
Identical to rb_warning(), except it takes additional "category" parameter.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_eTypeError
TypeError exception.
void rb_invalid_str(const char *str, const char *type)
Honestly I don't understand the name, but it raises an instance of rb_eArgError.
VALUE rb_eArgError
ArgumentError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
@ RB_WARN_CATEGORY_DEPRECATED
Warning is for deprecated features.
VALUE rb_cClass
Class class.
VALUE rb_cRational
Rational class.
VALUE rb_class_superclass(VALUE klass)
Returns the superclass of klass.
VALUE rb_class_get_superclass(VALUE klass)
Returns the superclass of a class.
VALUE rb_convert_type(VALUE val, int type, const char *tname, const char *method)
Converts an object into another type.
#define case_equal
call-seq: obj === other -> true or false
VALUE rb_Float(VALUE val)
This is the logic behind Kernel#Float.
VALUE rb_mKernel
Kernel module.
VALUE rb_check_to_int(VALUE val)
Identical to rb_check_to_integer(), except it uses #to_int for conversion.
VALUE rb_obj_reveal(VALUE obj, VALUE klass)
Make a hidden object visible again.
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,...
VALUE rb_cObject
Documented in include/ruby/internal/globals.h.
VALUE rb_any_to_s(VALUE obj)
Generates a textual representation of the given object.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
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 gi...
VALUE rb_cRefinement
Refinement class.
VALUE rb_cInteger
Module class.
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
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 ...
VALUE rb_check_to_float(VALUE val)
This is complicated.
static VALUE rb_obj_init_clone(int argc, VALUE *argv, VALUE obj)
Default implementation of #initialize_clone.
VALUE rb_cNilClass
NilClass class.
VALUE rb_Hash(VALUE val)
Equivalent to Kernel#Hash in Ruby.
VALUE rb_obj_frozen_p(VALUE obj)
Just calls RB_OBJ_FROZEN() inside.
VALUE rb_obj_init_copy(VALUE obj, VALUE orig)
Default implementation of #initialize_copy.
int rb_eql(VALUE obj1, VALUE obj2)
Checks for equality of the passed objects, in terms of Object#eql?.
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.
VALUE rb_Integer(VALUE val)
This is the logic behind Kernel#Integer.
VALUE rb_cFalseClass
FalseClass class.
VALUE rb_cNumeric
Numeric class.
VALUE rb_Array(VALUE val)
This is the logic behind Kernel#Array.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_obj_dup(VALUE obj)
Duplicates the given object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_cBasicObject
BasicObject class.
VALUE rb_cModule
Module class.
VALUE rb_class_inherited_p(VALUE mod, VALUE arg)
Determines if the given two modules are relatives.
VALUE rb_obj_is_instance_of(VALUE obj, VALUE c)
Queries if the given object is a direct instance of the given class.
VALUE rb_class_real(VALUE cl)
Finds a "real" class.
VALUE rb_obj_init_dup_clone(VALUE obj, VALUE orig)
Default implementation of #initialize_dup.
VALUE rb_to_float(VALUE val)
Identical to rb_check_to_float(), except it raises on error.
double rb_num2dbl(VALUE val)
Converts an instance of rb_cNumeric into C's double.
VALUE rb_equal(VALUE obj1, VALUE obj2)
This function is an optimised version of calling #==.
VALUE rb_obj_clone(VALUE obj)
Produces a shallow copy of the given object.
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.
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 th...
VALUE rb_obj_freeze(VALUE obj)
Just calls rb_obj_freeze_inline() inside.
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.
VALUE rb_class_search_ancestor(VALUE klass, VALUE super)
Internal header for Object.
VALUE rb_String(VALUE val)
This is the logic behind Kernel#String.
VALUE rb_cTrueClass
TrueClass class.
VALUE rb_to_int(VALUE val)
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
VALUE rb_obj_setup(VALUE obj, VALUE klass, VALUE type)
Fills common fields in the object.
#define RB_OBJ_WRITTEN(old, oldv, young)
Identical to RB_OBJ_WRITE(), except it doesn't write any values, but only a WB declaration.
int rb_enc_str_asciionly_p(VALUE str)
Queries if the passed string is "ASCII only".
ID rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
Identical to rb_check_id(), except it takes a pointer to a memory region instead of Ruby's string.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
Defines RBIMPL_HAS_BUILTIN.
#define rb_check_frozen
Just another name of rb_check_frozen.
int rb_is_instance_id(ID id)
Classifies the given ID, then sees if it is an instance variable.
int rb_is_const_id(ID id)
Classifies the given ID, then sees if it is a constant.
ID rb_id_attrset(ID id)
Calculates an ID of attribute writer.
int rb_is_local_id(ID id)
Classifies the given ID, then sees if it is a local variable.
VALUE rb_rational_num(VALUE rat)
Queries the numerator of the passed Rational.
VALUE rb_rational_den(VALUE rat)
Queries the denominator of the passed Rational.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_subseq(VALUE str, long beg, long len)
Identical to rb_str_substr(), except the numbers are interpreted as byte offsets instead of character...
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
VALUE rb_str_concat(VALUE dst, VALUE src)
Identical to rb_str_append(), except it also accepts an integer as a codepoint.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_intern(VALUE str)
Identical to rb_to_symbol(), except it assumes the receiver being an instance of RString.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_mod_remove_cvar(VALUE mod, VALUE name)
Resembles Module#remove_class_variable.
VALUE rb_obj_instance_variables(VALUE obj)
Resembles Object#instance_variables.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
VALUE rb_mod_remove_const(VALUE space, VALUE name)
Resembles Module#remove_const.
void rb_cvar_set(VALUE klass, ID name, VALUE val)
Assigns a value to a class variable.
VALUE rb_cvar_get(VALUE klass, ID name)
Obtains a value from a class variable.
VALUE rb_mod_constants(int argc, const VALUE *argv, VALUE recv)
Resembles Module#constants.
VALUE rb_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
void rb_const_set(VALUE space, ID name, VALUE val)
Names a constant.
VALUE rb_mod_name(VALUE mod)
Queries the name of a module.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
VALUE rb_const_get_at(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
VALUE rb_obj_remove_instance_variable(VALUE obj, VALUE name)
Resembles Object#remove_instance_variable.
st_index_t rb_ivar_count(VALUE obj)
Number of instance variables defined on an object.
VALUE rb_const_get_from(VALUE space, ID name)
Identical to rb_const_defined_at(), except it returns the actual defined value.
VALUE rb_ivar_defined(VALUE obj, ID name)
Queries if the instance variable is defined at the object.
int rb_const_defined_at(VALUE space, ID name)
Identical to rb_const_defined(), except it doesn't look for parent classes.
VALUE rb_mod_class_variables(int argc, const VALUE *argv, VALUE recv)
Resembles Module#class_variables.
VALUE rb_cvar_defined(VALUE klass, ID name)
Queries if the given class has the given class variable.
int rb_const_defined_from(VALUE space, ID name)
Identical to rb_const_defined(), except it returns false for private constants.
int rb_const_defined(VALUE space, ID name)
Queries if the constant is defined at the namespace.
VALUE(* rb_alloc_func_t)(VALUE klass)
This is the type of functions that ruby calls when trying to allocate an object.
void rb_undef_alloc_func(VALUE klass)
Deletes the allocator function of a class.
void rb_attr(VALUE klass, ID name, int need_reader, int need_writer, int honour_visibility)
This function resembles now-deprecated Module#attr.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
rb_alloc_func_t rb_get_alloc_func(VALUE klass)
Queries the allocator function of a class.
VALUE rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
Identical to rb_obj_instance_exec(), except it evaluates within the context of module.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
int rb_obj_respond_to(VALUE obj, ID mid, int private_p)
Identical to rb_respond_to(), except it additionally takes the visibility parameter.
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
const char * rb_id2name(ID id)
Retrieves the name mapped to the given id.
ID rb_intern_str(VALUE str)
Identical to rb_intern(), except it takes an instance of rb_cString.
#define strtod(s, e)
Just another name of ruby_strtod.
VALUE rb_f_sprintf(int argc, const VALUE *argv)
Identical to rb_str_format(), except how the arguments are arranged.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_str_catf(VALUE dst, const char *fmt,...)
Identical to rb_sprintf(), except it renders the output to the specified object rather than creating ...
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_ivar_foreach(VALUE q, int_type *w, VALUE e)
Iteration over each instance variable of the object.
void rb_copy_generic_ivar(VALUE clone, VALUE obj)
Copies the list of instance variables.
#define RARRAY_LEN
Just another name of rb_array_len.
#define RBASIC(obj)
Convenient casting macro.
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
#define RCLASS(obj)
Convenient casting macro.
#define ROBJECT(obj)
Convenient casting macro.
#define StringValue(v)
Ensures that the parameter object is a String.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
const char * rb_class2name(VALUE klass)
Queries the name of the passed class.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define InitVM(ext)
This macro is for internal use.
#define RB_PASS_KEYWORDS
Pass keywords, final argument should be a hash of keywords.
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
#define RB_NO_KEYWORDS
Do not pass keywords.
#define RTEST
This is an old name of RB_TEST.
#define _(args)
This was a transition path from K&R to ANSI.
uintptr_t VALUE
Type that represents a Ruby object.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.