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"
59static VALUE rb_cNilClass_to_s;
60static VALUE rb_cTrueClass_to_s;
61static VALUE rb_cFalseClass_to_s;
67#define id_match idEqTilde
68#define id_inspect idInspect
69#define id_init_copy idInitialize_copy
70#define id_init_clone idInitialize_clone
71#define id_init_dup idInitialize_dup
72#define id_const_missing idConst_missing
75#define CLASS_OR_MODULE_P(obj) \
76 (!SPECIAL_CONST_P(obj) && \
77 (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
85 RBASIC_CLEAR_CLASS(obj);
94 RBASIC_SET_CLASS(obj, klass);
103 RBASIC_SET_CLASS(obj, klass);
115#define case_equal rb_equal
124 if (obj1 == obj2)
return Qtrue;
125 result = rb_equal_opt(obj1, obj2);
129 return RBOOL(
RTEST(result));
137 if (obj1 == obj2)
return Qtrue;
138 result = rb_eql_opt(obj1, obj2);
142 return RBOOL(
RTEST(result));
148MJIT_FUNC_EXPORTED VALUE
149rb_obj_equal(VALUE obj1, VALUE obj2)
151 return RBOOL(obj1 == obj2);
154VALUE rb_obj_hash(VALUE obj);
160MJIT_FUNC_EXPORTED VALUE
170MJIT_FUNC_EXPORTED VALUE
171rb_obj_not_equal(VALUE obj1, VALUE obj2)
173 VALUE result =
rb_funcall(obj1, id_eq, 1, obj2);
211rb_obj_singleton_class(VALUE obj)
213 return rb_singleton_class(obj);
217MJIT_FUNC_EXPORTED
void
218rb_obj_copy_ivar(VALUE dest, VALUE obj)
224 if (
RBASIC(obj)->flags & ROBJECT_EMBED) {
225 src_buf =
ROBJECT(obj)->as.ary;
228 if (
RBASIC(dest)->flags & ROBJECT_EMBED) {
229 dst_buf =
ROBJECT(dest)->as.ary;
233 dst_buf =
ROBJECT(dest)->as.heap.ivptr;
238 uint32_t src_len =
ROBJECT(obj)->as.heap.numiv;
239 uint32_t dst_len =
ROBJECT(dest)->as.heap.numiv;
241 len = src_len < dst_len ? src_len : dst_len;
242 dst_buf =
ROBJECT(dest)->as.heap.ivptr;
243 src_buf =
ROBJECT(obj)->as.heap.ivptr;
246 MEMCPY(dst_buf, src_buf, VALUE, len);
250init_copy(VALUE dest, VALUE obj)
257 rb_copy_wb_protected_attribute(dest, obj);
261 rb_obj_copy_ivar(dest, obj);
265static VALUE immutable_obj_clone(VALUE obj, VALUE kwfreeze);
266static VALUE mutable_obj_clone(VALUE obj, VALUE kwfreeze);
267PUREFUNC(
static inline int special_object_p(VALUE obj));
269special_object_p(VALUE obj)
286obj_freeze_opt(VALUE freeze)
303 VALUE kwfreeze = obj_freeze_opt(freeze);
304 if (!special_object_p(obj))
305 return mutable_obj_clone(obj, kwfreeze);
306 return immutable_obj_clone(obj, kwfreeze);
311rb_immutable_obj_clone(
int argc, VALUE *argv, VALUE obj)
313 VALUE kwfreeze = rb_get_freeze_opt(argc, argv);
314 return immutable_obj_clone(obj, kwfreeze);
318rb_get_freeze_opt(
int argc, VALUE *argv)
320 static ID keyword_ids[1];
322 VALUE kwfreeze =
Qnil;
324 if (!keyword_ids[0]) {
331 kwfreeze = obj_freeze_opt(kwfreeze);
337immutable_obj_clone(VALUE obj, VALUE kwfreeze)
340 rb_raise(rb_eArgError,
"can't unfreeze %"PRIsVALUE,
346mutable_obj_clone(VALUE obj, VALUE kwfreeze)
348 VALUE clone, singleton;
353 singleton = rb_singleton_class_clone_and_attach(obj, clone);
354 RBASIC_SET_CLASS(clone, singleton);
356 rb_singleton_class_attached(singleton, clone);
359 init_copy(clone, obj);
368 static VALUE freeze_true_hash;
369 if (!freeze_true_hash) {
377 argv[1] = freeze_true_hash;
384 static VALUE freeze_false_hash;
385 if (!freeze_false_hash) {
393 argv[1] = freeze_false_hash;
398 rb_bug(
"invalid kwfreeze passed to mutable_obj_clone");
407 if (special_object_p(obj))
return obj;
408 return mutable_obj_clone(obj,
Qnil);
455 if (special_object_p(obj)) {
477rb_obj_itself(VALUE obj)
483rb_obj_size(VALUE
self, VALUE args, VALUE obj)
502 if (obj == orig)
return obj;
505 rb_raise(rb_eTypeError,
"initialize_copy should take same class object");
534 if (
rb_scan_args(argc, argv,
"1:", &orig, &opts) < argc) {
536 rb_get_freeze_opt(1, &opts);
558 str =
rb_sprintf(
"#<%"PRIsVALUE
":%p>", cname, (
void*)obj);
572 return rb_str_escape(str);
576 return rb_str_escape(str);
581inspect_i(st_data_t k, st_data_t v, st_data_t a)
584 VALUE value = (
VALUE)v;
585 VALUE str = (
VALUE)a;
588 if (
CLASS_OF(value) == 0)
return ST_CONTINUE;
604inspect_obj(VALUE obj, VALUE str,
int recur)
646rb_obj_inspect(VALUE obj)
652 str =
rb_sprintf(
"-<%"PRIsVALUE
":%p", c, (
void*)obj);
661class_or_module_required(VALUE c)
663 switch (OBJ_BUILTIN_TYPE(c)) {
670 rb_raise(rb_eTypeError,
"class or module required");
675static VALUE class_search_ancestor(VALUE cl, VALUE c);
697 c = class_or_module_required(c);
737 c = class_or_module_required(c);
738 return RBOOL(class_search_ancestor(cl, RCLASS_ORIGIN(c)));
742class_search_ancestor(VALUE cl, VALUE c)
745 if (cl == c || RCLASS_M_TBL(cl) == RCLASS_M_TBL(c))
756 cl = class_or_module_required(cl);
757 c = class_or_module_required(c);
758 return class_search_ancestor(cl, RCLASS_ORIGIN(c));
789#define rb_obj_class_inherited rb_obj_dummy1
812#define rb_obj_mod_method_added rb_obj_dummy1
839#define rb_obj_mod_method_removed rb_obj_dummy1
866#define rb_obj_mod_method_undefined rb_obj_dummy1
893#define rb_obj_singleton_method_added rb_obj_dummy1
922#define rb_obj_singleton_method_removed rb_obj_dummy1
947#define rb_obj_singleton_method_undefined rb_obj_dummy1
967#define rb_obj_mod_extended rb_obj_dummy1
990#define rb_obj_mod_included rb_obj_dummy1
1010#define rb_obj_mod_prepended rb_obj_dummy1
1020#define rb_obj_initialize rb_obj_dummy0
1033rb_obj_dummy0(VALUE
_)
1035 return rb_obj_dummy();
1039rb_obj_dummy1(VALUE _x, VALUE _y)
1041 return rb_obj_dummy();
1054 rb_warn_deprecated_to_remove_at(3.2,
"Object#tainted?", NULL);
1068 rb_warn_deprecated_to_remove_at(3.2,
"Object#taint", NULL);
1083 rb_warn_deprecated_to_remove_at(3.2,
"Object#untaint", NULL);
1097 rb_warn_deprecated_to_remove_at(3.2,
"Object#untrusted?", NULL);
1111 rb_warn_deprecated_to_remove_at(3.2,
"Object#untrust", NULL);
1126 rb_warn_deprecated_to_remove_at(3.2,
"Object#trust", NULL);
1133 rb_warn_deprecated_to_remove_at(3.2,
"rb_obj_infect", NULL);
1166 rb_bug(
"special consts should be frozen.");
1192MJIT_FUNC_EXPORTED VALUE
1193rb_nil_to_s(VALUE obj)
1195 return rb_cNilClass_to_s;
1240nil_inspect(VALUE obj)
1253nil_match(VALUE obj1, VALUE obj2)
1275MJIT_FUNC_EXPORTED VALUE
1276rb_true_to_s(VALUE obj)
1278 return rb_cTrueClass_to_s;
1291true_and(VALUE obj, VALUE obj2)
1293 return RBOOL(
RTEST(obj2));
1313true_or(VALUE obj, VALUE obj2)
1329true_xor(VALUE obj, VALUE obj2)
1352MJIT_FUNC_EXPORTED VALUE
1353rb_false_to_s(VALUE obj)
1355 return rb_cFalseClass_to_s;
1369false_and(VALUE obj, VALUE obj2)
1384#define false_or true_and
1397#define false_xor true_and
1423MJIT_FUNC_EXPORTED VALUE
1441rb_obj_match(VALUE obj1, VALUE obj2)
1459rb_obj_not_match(VALUE obj1, VALUE obj2)
1461 VALUE result =
rb_funcall(obj1, id_match, 1, obj2);
1485rb_obj_cmp(VALUE obj1, VALUE obj2)
1529MJIT_FUNC_EXPORTED VALUE
1530rb_mod_to_s(VALUE klass)
1533 VALUE refined_class, defined_at;
1539 if (CLASS_OR_MODULE_P(v)) {
1549 refined_class = rb_refinement_module_get_refined_class(klass);
1550 if (!
NIL_P(refined_class)) {
1555 CONST_ID(id_defined_at,
"__defined_at__");
1574rb_mod_freeze(VALUE mod)
1591rb_mod_eqq(VALUE mod, VALUE arg)
1610 if (mod == arg)
return Qtrue;
1612 rb_raise(rb_eTypeError,
"compared with non class/module");
1614 if (class_search_ancestor(mod, RCLASS_ORIGIN(arg))) {
1618 if (class_search_ancestor(arg, mod)) {
1636rb_mod_lt(VALUE mod, VALUE arg)
1638 if (mod == arg)
return Qfalse;
1656rb_mod_ge(VALUE mod, VALUE arg)
1658 if (!CLASS_OR_MODULE_P(arg)) {
1659 rb_raise(rb_eTypeError,
"compared with non class/module");
1677rb_mod_gt(VALUE mod, VALUE arg)
1679 if (mod == arg)
return Qfalse;
1680 return rb_mod_ge(mod, arg);
1696rb_mod_cmp(VALUE mod, VALUE arg)
1700 if (mod == arg)
return INT2FIX(0);
1701 if (!CLASS_OR_MODULE_P(arg)) {
1713static VALUE rb_mod_initialize_exec(VALUE module);
1742rb_mod_initialize(VALUE module)
1744 return rb_mod_initialize_exec(module);
1748rb_mod_initialize_exec(VALUE module)
1758rb_mod_initialize_clone(
int argc, VALUE* argv, VALUE clone)
1760 VALUE ret, orig, opts;
1799rb_class_initialize(
int argc, VALUE *argv, VALUE klass)
1804 rb_raise(rb_eTypeError,
"already initialized class");
1811 rb_check_inheritable(super);
1813 rb_raise(rb_eTypeError,
"can't inherit uninitialized class");
1816 RCLASS_SET_SUPER(klass, super);
1817 rb_make_metaclass(klass,
RBASIC(super)->klass);
1819 rb_mod_initialize_exec(klass);
1826rb_undefined_alloc(VALUE klass)
1828 rb_raise(rb_eTypeError,
"allocator undefined for %"PRIsVALUE,
1833static VALUE class_call_alloc_func(
rb_alloc_func_t allocator, VALUE klass);
1858rb_class_alloc_m(VALUE klass)
1862 rb_raise(rb_eTypeError,
"calling %"PRIsVALUE
".allocate is prohibited",
1865 return class_call_alloc_func(allocator, klass);
1869rb_class_alloc(VALUE klass)
1872 return class_call_alloc_func(allocator, klass);
1876class_get_alloc_func(VALUE klass)
1881 rb_raise(rb_eTypeError,
"can't instantiate uninitialized class");
1884 rb_raise(rb_eTypeError,
"can't create instance of singleton class");
1888 rb_undefined_alloc(klass);
1900 obj = (*allocator)(klass);
1903 rb_raise(rb_eTypeError,
"wrong instance allocation");
1912 return rb_class_alloc(klass);
1931 obj = rb_class_alloc(klass);
1943 obj = rb_class_alloc(klass);
1955 obj = rb_class_alloc(klass);
1977 rb_raise(rb_eTypeError,
"uninitialized class");
1991 return RCLASS(klass)->super;
1994static const char bad_instance_name[] =
"`%1$s' is not allowed as an instance variable name";
1995static const char bad_class_name[] =
"`%1$s' is not allowed as a class variable name";
1996static const char bad_const_name[] =
"wrong constant name %1$s";
1997static const char bad_attr_name[] =
"invalid attribute name `%1$s'";
1998#define wrong_constant_name bad_const_name
2001#define id_for_var(obj, name, type) id_for_setter(obj, name, type, bad_##type##_name)
2003#define id_for_setter(obj, name, type, message) \
2004 check_setter_id(obj, &(name), rb_is_##type##_id, rb_is_##type##_name, message, strlen(message))
2006check_setter_id(VALUE obj, VALUE *pname,
2007 int (*valid_id_p)(ID),
int (*valid_name_p)(VALUE),
2008 const char *message,
size_t message_len)
2011 VALUE name = *pname;
2013 if (
id ? !valid_id_p(
id) : !valid_name_p(name)) {
2014 rb_name_err_raise_str(rb_fstring_new(message, message_len),
2021rb_is_attr_name(VALUE name)
2023 return rb_is_local_name(name) || rb_is_const_name(name);
2033id_for_attr(VALUE obj, VALUE name)
2035 ID
id = id_for_var(obj, name, attr);
2055rb_mod_attr_reader(
int argc, VALUE *argv, VALUE klass)
2060 for (i=0; i<argc; i++) {
2061 ID
id = id_for_attr(klass, argv[i]);
2062 rb_attr(klass,
id, TRUE, FALSE, TRUE);
2073rb_mod_attr(
int argc, VALUE *argv, VALUE klass)
2075 if (argc == 2 && (argv[1] ==
Qtrue || argv[1] ==
Qfalse)) {
2076 ID
id = id_for_attr(klass, argv[0]);
2085 return rb_mod_attr_reader(argc, argv, klass);
2100rb_mod_attr_writer(
int argc, VALUE *argv, VALUE klass)
2105 for (i=0; i<argc; i++) {
2106 ID
id = id_for_attr(klass, argv[i]);
2107 rb_attr(klass,
id, FALSE, TRUE, TRUE);
2132rb_mod_attr_accessor(
int argc, VALUE *argv, VALUE klass)
2137 for (i=0; i<argc; i++) {
2138 ID
id = id_for_attr(klass, argv[i]);
2140 rb_attr(klass,
id, TRUE, TRUE, TRUE);
2188rb_mod_const_get(
int argc, VALUE *argv, VALUE mod)
2192 const char *pbeg, *p, *path, *pend;
2197 recur = (argc == 1) ?
Qtrue : argv[1];
2200 if (!rb_is_const_sym(name))
goto wrong_name;
2202 if (!
id)
return rb_const_missing(mod, name);
2210 rb_raise(rb_eArgError,
"invalid class path encoding (non ASCII)");
2216 if (p >= pend || !*p) {
2220 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2230 while (p < pend && *p !=
':') p++;
2232 if (pbeg == p)
goto wrong_name;
2237 if (p < pend && p[0] ==
':') {
2238 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2244 rb_raise(rb_eTypeError,
"%"PRIsVALUE
" does not refer to class/module",
2251 if (!rb_is_const_name(part)) {
2257 mod = rb_const_missing(mod, part);
2261 rb_mod_const_missing(mod, part);
2269 mod = rb_const_get_0(mod,
id, beglen > 0 || !
RTEST(recur),
RTEST(recur), FALSE);
2271 if (!
RTEST(recur)) {
2274 else if (beglen == 0) {
2286 rb_name_err_raise(wrong_constant_name, mod, name);
2310rb_mod_const_set(VALUE mod, VALUE name, VALUE value)
2312 ID
id = id_for_var(mod, name,
const);
2361rb_mod_const_defined(
int argc, VALUE *argv, VALUE mod)
2365 const char *pbeg, *p, *path, *pend;
2370 recur = (argc == 1) ?
Qtrue : argv[1];
2373 if (!rb_is_const_sym(name))
goto wrong_name;
2383 rb_raise(rb_eArgError,
"invalid class path encoding (non ASCII)");
2389 if (p >= pend || !*p) {
2393 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2403 while (p < pend && *p !=
':') p++;
2405 if (pbeg == p)
goto wrong_name;
2410 if (p < pend && p[0] ==
':') {
2411 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2419 if (!rb_is_const_name(part)) {
2433 mod = rb_const_search(mod,
id, beglen > 0 || !
RTEST(recur),
RTEST(recur), FALSE);
2436 if (!
RTEST(recur)) {
2439 if (p == pend)
return Qtrue;
2442 else if (beglen == 0) {
2445 if (p == pend)
return Qtrue;
2451 if (p == pend)
return Qtrue;
2457 rb_raise(rb_eTypeError,
"%"PRIsVALUE
" does not refer to class/module",
2465 rb_name_err_raise(wrong_constant_name, mod, name);
2521rb_mod_const_source_location(
int argc, VALUE *argv, VALUE mod)
2523 VALUE name, recur, loc =
Qnil;
2525 const char *pbeg, *p, *path, *pend;
2530 recur = (argc == 1) ?
Qtrue : argv[1];
2533 if (!rb_is_const_sym(name))
goto wrong_name;
2535 if (!
id)
return Qnil;
2536 return RTEST(recur) ? rb_const_source_location(mod,
id) : rb_const_source_location_at(mod, id);
2543 rb_raise(rb_eArgError,
"invalid class path encoding (non ASCII)");
2549 if (p >= pend || !*p) {
2553 if (p + 2 < pend && p[0] ==
':' && p[1] ==
':') {
2563 while (p < pend && *p !=
':') p++;
2565 if (pbeg == p)
goto wrong_name;
2570 if (p < pend && p[0] ==
':') {
2571 if (p + 2 >= pend || p[1] !=
':')
goto wrong_name;
2579 if (!rb_is_const_name(part)) {
2599 rb_raise(rb_eTypeError,
"%"PRIsVALUE
" does not refer to class/module",
2605 loc = rb_const_source_location(mod,
id);
2608 loc = rb_const_source_location_at(mod,
id);
2618 rb_name_err_raise(wrong_constant_name, mod, name);
2645rb_obj_ivar_get(VALUE obj, VALUE iv)
2647 ID
id = id_for_var(obj, iv, instance);
2679rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val)
2681 ID
id = id_for_var(obj, iv, instance);
2707rb_obj_ivar_defined(VALUE obj, VALUE iv)
2709 ID
id = id_for_var(obj, iv, instance);
2734rb_mod_cvar_get(VALUE obj, VALUE iv)
2736 ID
id = id_for_var(obj, iv,
class);
2739 rb_name_err_raise(
"uninitialized class variable %1$s in %2$s",
2766rb_mod_cvar_set(VALUE obj, VALUE iv, VALUE val)
2768 ID
id = id_for_var(obj, iv,
class);
2791rb_mod_cvar_defined(VALUE obj, VALUE iv)
2793 ID
id = id_for_var(obj, iv,
class);
2815rb_mod_singleton_p(VALUE klass)
2821static const struct conv_method_tbl {
2822 const char method[6];
2824} conv_method_names[] = {
2825#define M(n) {#n, (unsigned short)idTo_##n}
2840#define IMPLICIT_CONVERSIONS 7
2843conv_method_index(
const char *method)
2845 static const char prefix[] =
"to_";
2847 if (strncmp(prefix, method,
sizeof(prefix)-1) == 0) {
2848 const char *
const meth = &method[
sizeof(prefix)-1];
2850 for (i=0; i < numberof(conv_method_names); i++) {
2851 if (conv_method_names[i].method[0] == meth[0] &&
2852 strcmp(conv_method_names[i].method, meth) == 0) {
2857 return numberof(conv_method_names);
2861convert_type_with_id(VALUE val,
const char *tname, ID method,
int raise,
int index)
2867 ((index < 0 ? conv_method_index(
rb_id2name(method)) : index)
2868 < IMPLICIT_CONVERSIONS) ?
2869 "no implicit conversion of" :
"can't convert";
2870 const char *cname =
NIL_P(val) ?
"nil" :
2871 val ==
Qtrue ?
"true" :
2872 val ==
Qfalse ?
"false" :
2875 rb_raise(rb_eTypeError,
"%s %s into %s", msg, cname, tname);
2876 rb_raise(rb_eTypeError,
"%s %"PRIsVALUE
" into %s", msg,
2886convert_type(VALUE val,
const char *tname,
const char *method,
int raise)
2888 int i = conv_method_index(method);
2889 ID m = i < numberof(conv_method_names) ?
2890 conv_method_names[i].id :
rb_intern(method);
2891 return convert_type_with_id(val, tname, m,
raise, i);
2895NORETURN(
static void conversion_mismatch(VALUE,
const char *,
const char *, VALUE));
2897conversion_mismatch(VALUE val,
const char *tname,
const char *method, VALUE result)
2901 "can't convert %"PRIsVALUE
" to %s (%"PRIsVALUE
"#%s gives %"PRIsVALUE
")",
2911 v = convert_type(val, tname, method, TRUE);
2913 conversion_mismatch(val, tname, method, v);
2920rb_convert_type_with_id(VALUE val,
int type,
const char *tname, ID method)
2925 v = convert_type_with_id(val, tname, method, TRUE, -1);
2939 v = convert_type(val, tname, method, FALSE);
2942 conversion_mismatch(val, tname, method, v);
2948MJIT_FUNC_EXPORTED VALUE
2949rb_check_convert_type_with_id(VALUE val,
int type,
const char *tname, ID method)
2955 v = convert_type_with_id(val, tname, method, FALSE, -1);
2963#define try_to_int(val, mid, raise) \
2964 convert_type_with_id(val, "Integer", mid, raise, -1)
2966ALWAYS_INLINE(
static VALUE rb_to_integer_with_id_exception(VALUE val,
const char *method, ID mid,
int raise));
2969rb_to_integer_with_id_exception(VALUE val,
const char *method, ID mid,
int raise)
2974 v = try_to_int(val, mid,
raise);
2977 conversion_mismatch(val,
"Integer", method, v);
2981#define rb_to_integer(val, method, mid) \
2982 rb_to_integer_with_id_exception(val, method, mid, TRUE)
2990 v = convert_type(val,
"Integer", method, FALSE);
3000 return rb_to_integer(val,
"to_int", idTo_int);
3007 val = try_to_int(val, idTo_int, FALSE);
3013rb_check_to_i(VALUE val)
3016 val = try_to_int(val, idTo_i, FALSE);
3022rb_convert_to_integer(VALUE val,
int base,
int raise_exception)
3032 else if (! raise_exception) {
3036 rb_raise(rb_eArgError,
"base specified for non string value");
3041 if (!raise_exception && !isfinite(f))
return Qnil;
3049 return rb_str_convert_to_inum(val, base, TRUE, raise_exception);
3051 else if (
NIL_P(val)) {
3052 if (!raise_exception)
return Qnil;
3053 rb_raise(rb_eTypeError,
"can't convert nil into Integer");
3060 if (!raise_exception) {
3061 VALUE result =
rb_protect(rb_check_to_i, val, NULL);
3066 return rb_to_integer(val,
"to_i", idTo_i);
3072 return rb_convert_to_integer(val, 0, TRUE);
3076rb_check_integer_type(VALUE val)
3078 return rb_to_integer_with_id_exception(val,
"to_int", idTo_int, FALSE);
3082rb_bool_expected(VALUE obj,
const char *flagname)
3088 rb_raise(rb_eArgError,
"expected true or false as %s: %+"PRIsVALUE,
3095rb_opts_exception_p(VALUE opts,
int default_value)
3097 static const ID kwds[1] = {idException};
3100 return rb_bool_expected(exception,
"exception");
3101 return default_value;
3104#define opts_exception_p(opts) rb_opts_exception_p((opts), TRUE)
3141rb_f_integer(
int argc, VALUE *argv, VALUE obj)
3149 if (!
NIL_P(vbase)) {
3164 return rb_convert_to_integer(arg, base, opts_exception_p(opts));
3168rb_cstr_to_dbl_raise(
const char *p,
int badcheck,
int raise,
int *error)
3173 const char *ellipsis =
"";
3175 enum {max_width = 20};
3176#define OutOfRange() ((end - p > max_width) ? \
3177 (w = max_width, ellipsis = "...") : \
3178 (w = (int)(end - p), ellipsis = ""))
3184 if (!badcheck && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3189 if (errno == ERANGE) {
3191 rb_warning(
"Float %.*s%s out of range", w, p, ellipsis);
3201 char buf[DBL_DIG * 4 + 10];
3203 char *
const init_e = buf + DBL_DIG * 4;
3206 int dot_seen = FALSE;
3208 switch (*p) {
case '+':
case '-': prev = *n++ = *p++;}
3211 while (*++p ==
'0');
3213 while (p < end && n < e) prev = *n++ = *p++;
3218 if (badcheck)
goto bad;
3223 if (e == init_e && (prev ==
'e' || prev ==
'E' || prev ==
'p' || prev ==
'P')) {
3224 e = buf +
sizeof(buf) - 1;
3226 switch (*p) {
case '+':
case '-': prev = *n++ = *p++;}
3229 while (*++p ==
'0');
3236 if (badcheck)
goto bad;
3240 else if (prev ==
'.' ? dot_seen++ : !
ISDIGIT(prev)) {
3241 if (badcheck)
goto bad;
3244 if (n < e) *n++ = prev;
3249 if (!badcheck && p[0] ==
'0' && (p[1] ==
'x' || p[1] ==
'X')) {
3254 if (errno == ERANGE) {
3256 rb_warning(
"Float %.*s%s out of range", w, p, ellipsis);
3260 if (!end || p == end)
goto bad;
3261 while (*end &&
ISSPACE(*end)) end++;
3265 if (errno == ERANGE) {
3268 rb_raise(rb_eArgError,
"Float %.*s%s out of range", w, q, ellipsis);
3278 if (error) *error = 1;
3286 return rb_cstr_to_dbl_raise(p, badcheck, TRUE, NULL);
3290rb_str_to_dbl_raise(VALUE str,
int badcheck,
int raise,
int *error)
3301 if (badcheck && memchr(s,
'\0', len)) {
3303 rb_raise(rb_eArgError,
"string for Float contains null byte");
3305 if (error) *error = 1;
3310 char *p =
ALLOCV(v, (
size_t)len + 1);
3316 ret = rb_cstr_to_dbl_raise(s, badcheck,
raise, error);
3322FUNC_MINIMIZED(
double rb_str_to_dbl(VALUE str,
int badcheck));
3327 return rb_str_to_dbl_raise(str, badcheck, TRUE, NULL);
3331#define fix2dbl_without_to_f(x) (double)FIX2LONG(x)
3332#define big2dbl_without_to_f(x) rb_big2dbl(x)
3333#define int2dbl_without_to_f(x) \
3334 (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : big2dbl_without_to_f(x))
3335#define num2dbl_without_to_f(x) \
3336 (FIXNUM_P(x) ? fix2dbl_without_to_f(x) : \
3337 RB_BIGNUM_TYPE_P(x) ? big2dbl_without_to_f(x) : \
3338 (Check_Type(x, T_FLOAT), RFLOAT_VALUE(x)))
3340rat2dbl_without_to_f(VALUE x)
3344 return num2dbl_without_to_f(num) / num2dbl_without_to_f(den);
3347#define special_const_to_float(val, pre, post) \
3350 rb_raise_static(rb_eTypeError, pre "nil" post); \
3352 rb_raise_static(rb_eTypeError, pre "true" post); \
3354 rb_raise_static(rb_eTypeError, pre "false" post); \
3359conversion_to_float(VALUE val)
3361 special_const_to_float(val,
"can't convert ",
" into Float");
3365implicit_conversion_to_float(VALUE val)
3367 special_const_to_float(val,
"no implicit conversion to float from ",
"");
3371to_float(VALUE *valp,
int raise_exception)
3376 *valp =
DBL2NUM(fix2dbl_without_to_f(val));
3382 else if (raise_exception) {
3383 conversion_to_float(val);
3392 *valp =
DBL2NUM(big2dbl_without_to_f(val));
3395 *valp =
DBL2NUM(rat2dbl_without_to_f(val));
3405convert_type_to_float_protected(VALUE val)
3407 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3411rb_convert_to_float(VALUE val,
int raise_exception)
3413 switch (to_float(&val, raise_exception)) {
3417 if (!raise_exception) {
3419 double x = rb_str_to_dbl_raise(val, TRUE, raise_exception, &e);
3428 if (!raise_exception) {
3430 VALUE result =
rb_protect(convert_type_to_float_protected, val, &state);
3435 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3438FUNC_MINIMIZED(VALUE
rb_Float(VALUE val));
3443 return rb_convert_to_float(val, TRUE);
3449 return rb_convert_to_float(arg, TRUE);
3455 int exception = rb_bool_expected(opts,
"exception");
3456 return rb_convert_to_float(arg, exception);
3460numeric_to_float(VALUE val)
3463 rb_raise(rb_eTypeError,
"can't convert %"PRIsVALUE
" into Float",
3466 return rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3472 switch (to_float(&val, TRUE)) {
3476 return numeric_to_float(val);
3486 return rb_check_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3490basic_to_f_p(VALUE klass)
3497rb_num_to_dbl(VALUE val)
3502 return fix2dbl_without_to_f(val);
3505 return rb_float_flonum_value(val);
3508 conversion_to_float(val);
3514 return rb_float_noflonum_value(val);
3517 return big2dbl_without_to_f(val);
3521 return rat2dbl_without_to_f(val);
3527 val = numeric_to_float(val);
3536 return fix2dbl_without_to_f(val);
3539 return rb_float_flonum_value(val);
3542 implicit_conversion_to_float(val);
3548 return rb_float_noflonum_value(val);
3550 return big2dbl_without_to_f(val);
3552 return rat2dbl_without_to_f(val);
3554 rb_raise(rb_eTypeError,
"no implicit conversion to float from string");
3559 val = rb_convert_type_with_id(val,
T_FLOAT,
"Float", id_to_f);
3568 tmp = rb_convert_type_with_id(val,
T_STRING,
"String", idTo_s);
3587rb_f_string(VALUE obj, VALUE arg)
3598 tmp = rb_check_to_array(val);
3627rb_f_array(VALUE obj, VALUE arg)
3665rb_f_hash(VALUE obj, VALUE arg)
3679dig_basic_p(VALUE obj,
struct dig_method *cache)
3682 if (klass != cache->klass) {
3683 cache->klass = klass;
3686 return cache->basic;
3690no_dig_method(
int found, VALUE recv, ID mid,
int argc,
const VALUE *argv, VALUE data)
3693 rb_raise(rb_eTypeError,
"%"PRIsVALUE
" does not have #dig method",
3700rb_obj_dig(
int argc, VALUE *argv, VALUE obj, VALUE notfound)
3702 struct dig_method hash = {
Qnil}, ary = {
Qnil}, strt = {
Qnil};
3704 for (; argc > 0; ++argv, --argc) {
3705 if (
NIL_P(obj))
return notfound;
3709 if (dig_basic_p(obj, &hash)) {
3715 if (dig_basic_p(obj, &ary)) {
3716 obj = rb_ary_at(obj, *argv);
3721 if (dig_basic_p(obj, &strt)) {
3722 obj = rb_struct_lookup(obj, *argv);
3730 return rb_check_funcall_with_hook_kw(obj, id_dig, argc, argv,
3999f_sprintf(
int c,
const VALUE *v, VALUE
_)
4269 Init_class_hierarchy();
4540 rb_class_public_instance_methods, -1);
4542 rb_class_protected_instance_methods, -1);
4544 rb_class_private_instance_methods, -1);
4554 rb_mod_const_missing, 1);
4603#include "kernel.rbinc"
4604#include "nilclass.rbinc"
#define rb_define_private_method(klass, mid, func, arity)
Defines klass#mid and makes it private.
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_define_module(const char *name)
Defines a top-level module.
VALUE rb_class_inherited(VALUE, VALUE)
Calls Class::inherited.
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_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines 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.
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
#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 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_category_warn(rb_warning_category_t cat, const char *fmt,...)
Identical to rb_category_warning(), except it reports always regardless of runtime -W flag.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
void rb_category_warning(rb_warning_category_t cat, 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.
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.
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_obj_taint(VALUE obj)
VALUE rb_obj_trust(VALUE obj)
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.
void rb_obj_infect(VALUE victim, VALUE carrier)
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_obj_untrust(VALUE obj)
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_obj_untrusted(VALUE obj)
VALUE rb_String(VALUE val)
This is the logic behind Kernel#String.
VALUE rb_cTrueClass
TrueClass class.
VALUE rb_obj_untaint(VALUE obj)
VALUE rb_obj_tainted(VALUE obj)
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.
rb_encoding * rb_default_internal_encoding(void)
Queries the "default internal" encoding.
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
static bool rb_enc_asciicompat(rb_encoding *enc)
Queries if the passed encoding is in some sense compatible with ASCII.
rb_encoding * rb_default_external_encoding(void)
Queries the "default external" encoding.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
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_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
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.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
void rb_gc_register_mark_object(VALUE object)
Inform the garbage collector that object is a live Ruby object that should not be moved.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_dbl2big(double d)
Converts a C's double into a bignum.
#define rb_check_frozen
Just another name of rb_check_frozen.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
void rb_obj_call_init_kw(VALUE, int, const VALUE *, int)
Identical to rb_obj_call_init(), except you can specify how to handle the last element of the given a...
void rb_gc_copy_finalizer(VALUE dst, VALUE src)
Copy&paste an object's finaliser to another.
VALUE rb_check_hash_type(VALUE obj)
Try converting an object to its hash representation using its to_hash method, if any.
VALUE rb_hash_aref(VALUE hash, VALUE key)
Queries the given key in the given hash table.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
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_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
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_cat2(VALUE, const char *)
Just another name of rb_str_cat_cstr.
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_ivar_foreach(VALUE obj, int(*func)(ID name, VALUE val, st_data_t arg), st_data_t arg)
Iterates over an object's instance variables.
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.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
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.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
#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_copy_generic_ivar(VALUE clone, VALUE obj)
Copies the list of instance variables.
#define RARRAY_LEN
Just another name of rb_array_len.
static VALUE RBASIC_CLASS(VALUE obj)
Queries the class of an object.
#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.
@ ROBJECT_EMBED_LEN_MAX
Max possible number of instance variables that can be embedded.
#define StringValue(v)
Ensures that the parameter object is a String.
#define StringValuePtr(v)
Identical to StringValue, except it returns a char*.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
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 ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static bool RB_FLOAT_TYPE_P(VALUE obj)
Queries if the object is an instance of rb_cFloat.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.