12#include "ruby/internal/config.h"
23#include "internal/array.h"
24#include "internal/compar.h"
25#include "internal/enum.h"
26#include "internal/enumerator.h"
27#include "internal/error.h"
28#include "internal/numeric.h"
29#include "internal/range.h"
32static ID id_beg, id_end, id_excl;
38static VALUE r_cover_p(VALUE, VALUE, VALUE, VALUE);
40#define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
41#define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
42#define RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
44#define EXCL(r) RTEST(RANGE_EXCL(r))
47range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
54 rb_raise(rb_eArgError,
"bad value for range");
57 RANGE_SET_EXCL(range, exclude_end);
58 RANGE_SET_BEG(range, beg);
59 RANGE_SET_END(range, end);
71 range_init(range, beg, end, RBOOL(exclude_end));
76range_modify(VALUE range)
80 if (RANGE_EXCL(range) !=
Qnil) {
81 rb_name_err_raise(
"`initialize' called twice", range,
ID2SYM(idInitialize));
101range_initialize(
int argc, VALUE *argv, VALUE range)
103 VALUE beg, end, flags;
107 range_init(range, beg, end, RBOOL(
RTEST(flags)));
113range_initialize_copy(VALUE range, VALUE orig)
116 rb_struct_init_copy(range, orig);
133range_exclude_end_p(VALUE range)
135 return RBOOL(EXCL(range));
139recursive_equal(VALUE range, VALUE obj,
int recur)
141 if (recur)
return Qtrue;
142 if (!rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
144 if (!rb_equal(RANGE_END(range), RANGE_END(obj)))
147 return RBOOL(EXCL(range) == EXCL(obj));
183range_eq(VALUE range, VALUE obj)
199r_less(VALUE a, VALUE b)
209recursive_eql(VALUE range, VALUE obj,
int recur)
211 if (recur)
return Qtrue;
212 if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
214 if (!rb_eql(RANGE_END(range), RANGE_END(obj)))
217 return RBOOL(EXCL(range) == EXCL(obj));
251range_eql(VALUE range, VALUE obj)
272range_hash(VALUE range)
274 st_index_t hash = EXCL(range);
289range_each_func(VALUE range,
int (*func)(VALUE, VALUE), VALUE arg)
292 VALUE b = RANGE_BEG(range);
293 VALUE e = RANGE_END(range);
297 while (r_less(v, e) < 0) {
298 if ((*func)(v, arg))
break;
303 while ((c = r_less(v, e)) <= 0) {
304 if ((*func)(v, arg))
break;
312step_i_iter(VALUE arg)
314 VALUE *iter = (VALUE *)arg;
317 iter[0] -=
INT2FIX(1) & ~FIXNUM_FLAG;
322 if (iter[0] !=
INT2FIX(0))
return false;
328sym_step_i(VALUE i, VALUE arg)
330 if (step_i_iter(arg)) {
337step_i(VALUE i, VALUE arg)
339 if (step_i_iter(arg)) {
346discrete_object_p(VALUE obj)
352linear_object_p(VALUE obj)
363 if (rb_obj_is_kind_of(obj,
rb_cNumeric))
return TRUE;
364 if (rb_obj_is_kind_of(obj,
rb_cTime))
return TRUE;
369check_step_domain(VALUE step)
374 step = rb_to_int(step);
378 rb_raise(rb_eArgError,
"step can't be negative");
381 rb_raise(rb_eArgError,
"step can't be 0");
387range_step_size(VALUE range, VALUE args, VALUE eobj)
389 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
396 return ruby_num_interval_step_size(b, e, step, EXCL(range));
439range_step(
int argc, VALUE *argv, VALUE range)
441 VALUE b, e, step, tmp;
443 b = RANGE_BEG(range);
444 e = RANGE_END(range);
449 step = rb_to_int(step);
451 if (rb_equal(step,
INT2FIX(0))) {
452 rb_raise(rb_eArgError,
"step can't be 0");
455 const VALUE b_num_p = rb_obj_is_kind_of(b,
rb_cNumeric);
456 const VALUE e_num_p = rb_obj_is_kind_of(e,
rb_cNumeric);
457 if ((b_num_p && (
NIL_P(e) || e_num_p)) || (
NIL_P(b) && e_num_p)) {
459 range_step_size, b, e, step, EXCL(range));
465 step = check_step_domain(step);
466 VALUE iter[2] = {
INT2FIX(1), step};
488 if (i + unit < i)
break;
496 rb_str_upto_endless_each(b, sym_step_i, (VALUE)iter);
499 rb_str_upto_each(b,
rb_sym2str(e), EXCL(range), sym_step_i, (VALUE)iter);
502 else if (ruby_float_step(b, e, step, EXCL(range), TRUE)) {
508 ID op = EXCL(range) ?
'<' : idLE;
524 rb_str_upto_endless_each(b, step_i, (VALUE)iter);
527 rb_str_upto_each(b, e, EXCL(range), step_i, (VALUE)iter);
531 if (!discrete_object_p(b)) {
532 rb_raise(rb_eTypeError,
"can't iterate from %s",
535 range_each_func(range, step_i, (VALUE)iter);
569range_percent_step(VALUE range, VALUE step)
571 return range_step(1, &step, range);
574#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
581int64_as_double_to_num(int64_t i)
583 union int64_double convert;
595double_as_int64(
double d)
597 union int64_double convert;
599 return d < 0 ? -convert.i : convert.i;
614bsearch_integer_range(VALUE beg, VALUE end,
int excl)
616 VALUE satisfied =
Qnil;
619#define BSEARCH_CHECK(expr) \
621 VALUE val = (expr); \
622 VALUE v = rb_yield(val); \
624 if (v == INT2FIX(0)) return val; \
625 smaller = (SIGNED_VALUE)v < 0; \
627 else if (v == Qtrue) { \
631 else if (!RTEST(v)) { \
634 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
635 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
636 if (!cmp) return val; \
640 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
641 " (must be numeric, true, false or nil)", \
646 VALUE low = rb_to_int(beg);
647 VALUE high = rb_to_int(end);
665 if (rb_equal(low, org_high)) {
667 if (!smaller)
return Qnil;
683range_bsearch(VALUE range)
685 VALUE beg, end, satisfied =
Qnil;
702#define BSEARCH(conv) \
704 RETURN_ENUMERATOR(range, 0, 0); \
705 if (EXCL(range)) high--; \
707 while (low < high) { \
708 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
709 : (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
710 BSEARCH_CHECK(conv(mid)); \
718 if (low == org_high) { \
719 BSEARCH_CHECK(conv(low)); \
720 if (!smaller) return Qnil; \
726 beg = RANGE_BEG(range);
727 end = RANGE_END(range);
735#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
737 int64_t low = double_as_int64(
NIL_P(beg) ? -HUGE_VAL :
RFLOAT_VALUE(rb_Float(beg)));
738 int64_t high = double_as_int64(
NIL_P(end) ? HUGE_VAL :
RFLOAT_VALUE(rb_Float(end)));
739 int64_t mid, org_high;
740 BSEARCH(int64_as_double_to_num);
743 else if (is_integer_p(beg) && is_integer_p(end)) {
745 return bsearch_integer_range(beg, end, EXCL(range));
747 else if (is_integer_p(beg) &&
NIL_P(end)) {
754 return bsearch_integer_range(beg, mid, 0);
759 else if (
NIL_P(beg) && is_integer_p(end)) {
766 return bsearch_integer_range(mid, end, 0);
778each_i(VALUE v, VALUE arg)
785sym_each_i(VALUE v, VALUE arg)
807range_size(VALUE range)
809 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
812 return ruby_num_interval_step_size(b, e,
INT2FIX(1), EXCL(range));
840range_to_a(VALUE range)
842 if (
NIL_P(RANGE_END(range))) {
843 rb_raise(rb_eRangeError,
"cannot convert endless range to an array");
849range_enum_size(VALUE range, VALUE args, VALUE eobj)
851 return range_size(range);
856range_each_bignum_endless(VALUE beg)
866range_each_fixnum_endless(VALUE beg)
877range_each_fixnum_loop(VALUE beg, VALUE end, VALUE range)
879 long lim =
FIX2LONG(end) + !EXCL(range);
880 for (
long i =
FIX2LONG(beg); i < lim; i++) {
904range_each(VALUE range)
911 beg = RANGE_BEG(range);
912 end = RANGE_END(range);
915 range_each_fixnum_endless(beg);
918 return range_each_fixnum_loop(beg, end, range);
927 if (
NIL_P(end)) range_each_fixnum_endless(beg);
928 if (
FIXNUM_P(end))
return range_each_fixnum_loop(beg, end, range);
931 if (
NIL_P(end)) range_each_bignum_endless(beg);
965 rb_str_upto_endless_each(beg, sym_each_i, 0);
968 rb_str_upto_each(beg,
rb_sym2str(end), EXCL(range), sym_each_i, 0);
976 rb_str_upto_each(tmp, end, EXCL(range), each_i, 0);
979 rb_str_upto_endless_each(tmp, each_i, 0);
983 if (!discrete_object_p(beg)) {
984 rb_raise(rb_eTypeError,
"can't iterate from %s",
988 range_each_func(range, each_i, 0);
1010range_begin(VALUE range)
1012 return RANGE_BEG(range);
1031range_end(VALUE range)
1033 return RANGE_END(range);
1040 VALUE *ary = (VALUE *)cbarg;
1075range_first(
int argc, VALUE *argv, VALUE range)
1079 if (
NIL_P(RANGE_BEG(range))) {
1080 rb_raise(rb_eRangeError,
"cannot get the first element of beginless range");
1082 if (argc == 0)
return RANGE_BEG(range);
1093rb_int_range_last(
int argc, VALUE *argv, VALUE range)
1095 static const VALUE ONE =
INT2FIX(1);
1097 VALUE b, e, len_1, len, nv, ary;
1103 b = RANGE_BEG(range);
1104 e = RANGE_END(range);
1109 len_1 = rb_int_minus(e, b);
1111 e = rb_int_minus(e, ONE);
1115 len = rb_int_plus(len_1, ONE);
1118 if (FIXNUM_ZERO_P(len) || rb_num_negative_p(len)) {
1125 rb_raise(rb_eArgError,
"negative array size");
1129 if (
RTEST(rb_int_gt(nv, len))) {
1135 b = rb_int_minus(e, nv);
1137 b = rb_int_plus(b, ONE);
1181range_last(
int argc, VALUE *argv, VALUE range)
1185 if (
NIL_P(RANGE_END(range))) {
1186 rb_raise(rb_eRangeError,
"cannot get the last element of endless range");
1188 if (argc == 0)
return RANGE_END(range);
1190 b = RANGE_BEG(range);
1191 e = RANGE_END(range);
1194 return rb_int_range_last(argc, argv, range);
1196 return rb_ary_last(argc, argv, rb_Array(range));
1282range_min(
int argc, VALUE *argv, VALUE range)
1284 if (
NIL_P(RANGE_BEG(range))) {
1285 rb_raise(rb_eRangeError,
"cannot get the minimum of beginless range");
1289 if (
NIL_P(RANGE_END(range))) {
1290 rb_raise(rb_eRangeError,
"cannot get the minimum of endless range with custom comparison method");
1294 else if (argc != 0) {
1295 return range_first(argc, argv, range);
1299 VALUE b = RANGE_BEG(range);
1300 VALUE e = RANGE_END(range);
1301 int c =
NIL_P(e) ? -1 : OPTIMIZED_CMP(b, e, cmp_opt);
1303 if (c > 0 || (c == 0 && EXCL(range)))
1391range_max(
int argc, VALUE *argv, VALUE range)
1393 VALUE e = RANGE_END(range);
1396 if (
NIL_P(RANGE_END(range))) {
1397 rb_raise(rb_eRangeError,
"cannot get the maximum of endless range");
1400 VALUE b = RANGE_BEG(range);
1404 rb_raise(rb_eRangeError,
"cannot get the maximum of beginless range with custom comparison method");
1410 int c =
NIL_P(b) ? -1 : OPTIMIZED_CMP(b, e, cmp_opt);
1416 rb_raise(rb_eTypeError,
"cannot exclude non Integer end value");
1418 if (c == 0)
return Qnil;
1420 rb_raise(rb_eTypeError,
"cannot exclude end value with non Integer begin value");
1478range_minmax(VALUE range)
1495 if (rb_obj_is_kind_of(range,
rb_cRange)) {
1496 b = RANGE_BEG(range);
1497 e = RANGE_END(range);
1500 else if (
RTEST(rb_obj_is_kind_of(range, rb_cArithSeq))) {
1542rb_range_component_beg_len(VALUE b, VALUE e,
int excl,
1543 long *begp,
long *lenp,
long len,
int err)
1549 if (
NIL_P(e)) excl = 0;
1559 if (err == 0 || err == 2) {
1586 VALUE res = rb_range_component_beg_len(b, e, excl, begp, lenp, len, err);
1587 if (
NIL_P(res) && err) {
1588 rb_raise(rb_eRangeError,
"%+"PRIsVALUE
" out of range", range);
1616range_to_s(VALUE range)
1630inspect_range(VALUE range, VALUE dummy,
int recur)
1632 VALUE str, str2 =
Qundef;
1635 return rb_str_new2(EXCL(range) ?
"(... ... ...)" :
"(... .. ...)");
1637 if (!
NIL_P(RANGE_BEG(range)) ||
NIL_P(RANGE_END(range))) {
1638 str =
rb_str_dup(rb_inspect(RANGE_BEG(range)));
1644 if (
NIL_P(RANGE_BEG(range)) || !
NIL_P(RANGE_END(range))) {
1645 str2 = rb_inspect(RANGE_END(range));
1675range_inspect(VALUE range)
1680static VALUE range_include_internal(VALUE range, VALUE val,
int string_use_cover);
1722range_eqq(VALUE range, VALUE val)
1724 VALUE ret = range_include_internal(range, val, 1);
1725 if (ret !=
Qundef)
return ret;
1726 return r_cover_p(range, RANGE_BEG(range), RANGE_END(range), val);
1762range_include(VALUE range, VALUE val)
1764 VALUE ret = range_include_internal(range, val, 0);
1765 if (ret !=
Qundef)
return ret;
1770range_include_internal(VALUE range, VALUE val,
int string_use_cover)
1772 VALUE beg = RANGE_BEG(range);
1773 VALUE end = RANGE_END(range);
1775 linear_object_p(beg) || linear_object_p(end);
1780 return r_cover_p(range, beg, end, val);
1784 if (string_use_cover) {
1785 return r_cover_p(range, beg, end, val);
1788 VALUE rb_str_include_range_p(VALUE beg, VALUE end, VALUE val, VALUE exclusive);
1789 return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
1792 else if (
NIL_P(beg)) {
1795 return RBOOL(
rb_cmpint(r, val, end) <= 0);
1797 else if (
NIL_P(end)) {
1800 return RBOOL(
rb_cmpint(r, beg, val) <= 0);
1806static int r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val);
1893range_cover(VALUE range, VALUE val)
1897 beg = RANGE_BEG(range);
1898 end = RANGE_END(range);
1900 if (rb_obj_is_kind_of(val,
rb_cRange)) {
1901 return RBOOL(r_cover_range_p(range, beg, end, val));
1903 return r_cover_p(range, beg, end, val);
1913r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val)
1915 VALUE val_beg, val_end, val_max;
1918 val_beg = RANGE_BEG(val);
1919 val_end = RANGE_END(val);
1921 if (!
NIL_P(end) &&
NIL_P(val_end))
return FALSE;
1922 if (!
NIL_P(beg) &&
NIL_P(val_beg))
return FALSE;
1923 if (!
NIL_P(val_beg) && !
NIL_P(val_end) && r_less(val_beg, val_end) > (EXCL(val) ? -1 : 0))
return FALSE;
1924 if (!
NIL_P(val_beg) && !r_cover_p(range, beg, end, val_beg))
return FALSE;
1926 cmp_end = r_less(end, val_end);
1928 if (EXCL(range) == EXCL(val)) {
1929 return cmp_end >= 0;
1931 else if (EXCL(range)) {
1934 else if (cmp_end >= 0) {
1938 val_max =
rb_rescue2(r_call_max, val, 0,
Qnil, rb_eTypeError, (VALUE)0);
1939 if (
NIL_P(val_max))
return FALSE;
1941 return r_less(end, val_max) >= 0;
1945r_cover_p(VALUE range, VALUE beg, VALUE end, VALUE val)
1947 if (
NIL_P(beg) || r_less(beg, val) <= 0) {
1948 int excl = EXCL(range);
1949 if (
NIL_P(end) || r_less(val, end) <= -excl)
1956range_dumper(VALUE range)
1958 VALUE v = rb_obj_alloc(rb_cObject);
1967range_loader(VALUE range, VALUE obj)
1969 VALUE beg, end, excl;
1972 rb_raise(rb_eTypeError,
"not a dumped range object");
1975 range_modify(range);
1980 range_init(range, beg, end, RBOOL(
RTEST(excl)));
1986range_alloc(VALUE klass)
2025range_count(
int argc, VALUE *argv, VALUE range)
2037 else if (
NIL_P(RANGE_END(range))) {
2041 else if (
NIL_P(RANGE_BEG(range))) {
2274 "Range", rb_cObject, range_alloc,
2275 "begin",
"end",
"excl", NULL);
#define RB_LIKELY(x)
Asserts that the given Boolean expression likely holds.
void rb_include_module(VALUE klass, VALUE module)
Includes a module to a class.
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.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define RB_INTEGER_TYPE_P
Old name of rb_integer_type_p.
#define RFLOAT_VALUE
Old name of rb_float_value.
#define T_STRING
Old name of RUBY_T_STRING.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#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 CLASS_OF
Old name of rb_class_of.
#define FIXABLE
Old name of RB_FIXABLE.
#define LONG2FIX
Old name of RB_INT2FIX.
#define ASSUME
Old name of RBIMPL_ASSUME.
#define LONG2NUM
Old name of RB_LONG2NUM.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define FIX2LONG
Old name of RB_FIX2LONG.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define POSFIXABLE
Old name of RB_POSFIXABLE.
#define DBL2NUM
Old name of rb_float_new.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
#define NUM2LONG
Old name of RB_NUM2LONG.
#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 SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
void rb_iter_break(void)
Breaks from a block.
VALUE rb_cTime
Time class.
VALUE rb_mEnumerable
Enumerable module.
VALUE rb_cNumeric
Numeric class.
VALUE rb_cRange
Range class.
VALUE rb_check_to_integer(VALUE val, const char *mid)
Identical to rb_check_convert_type(), except the return value type is fixed to rb_cInteger.
#define RUBY_FIXNUM_MAX
Maximum possible value that a fixnum can represent.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
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.
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_assoc_new(VALUE car, VALUE cdr)
Identical to rb_ary_new_from_values(), except it expects exactly two parameters.
VALUE rb_big_plus(VALUE x, VALUE y)
Performs addition of the passed two objects.
VALUE rb_big_cmp(VALUE lhs, VALUE rhs)
Compares the passed two bignums.
int rb_cmpint(VALUE val, VALUE a, VALUE b)
Canonicalises the passed val, which is the return value of a <=> b, into C's {-1, 0,...
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
This roughly resembles return enum_for(__callee__) unless block_given?.
#define RETURN_ENUMERATOR(obj, argc, argv)
Identical to RETURN_SIZED_ENUMERATOR(), except its size is unknown.
#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.
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
VALUE rb_hash(VALUE obj)
Calculates a message authentication code of the passed object.
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
Deconstructs a range into its components.
VALUE rb_range_new(VALUE beg, VALUE end, int excl)
Creates a new Range.
VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
Deconstructs a numerical range.
#define rb_hash_uint(h, i)
Just another name of st_hash_uint.
#define rb_hash_end(h)
Just another name of st_hash_end.
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_dup(VALUE str)
Duplicates a string.
VALUE rb_str_cat(VALUE dst, const char *src, long srclen)
Destructively appends the passed contents to the string.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
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_struct_define_without_accessor(const char *name, VALUE super, rb_alloc_func_t func,...)
Identical to rb_struct_define(), except it does not define accessor methods.
VALUE rb_struct_alloc_noinit(VALUE klass)
Allocates an instance of the given class.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_exec_recursive_paired(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE p, VALUE h)
Identical to rb_exec_recursive(), except it checks for the recursion on the ordered pair of { g,...
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_ivar_get(VALUE obj, ID name)
Identical to rb_iv_get(), except it accepts the name as an ID instead of a C string.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
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.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
RBIMPL_ATTR_NORETURN() void rb_eof_error(void)
Utility function to raise rb_eEOFError.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t proc, VALUE data2)
Identical to rb_funcallv(), except it additionally passes a function as a block.
VALUE rb_yield(VALUE val)
Yields the block.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
#define RARRAY_AREF(a, i)
#define RBASIC(obj)
Convenient casting macro.
#define RBIGNUM_SIGN
Just another name of rb_big_sign.
static bool RBIGNUM_NEGATIVE_P(VALUE b)
Checks if the bignum is negative.
static bool RBIGNUM_POSITIVE_P(VALUE b)
Checks if the bignum is positive.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define RTEST
This is an old name of RB_TEST.
static bool RB_FLOAT_TYPE_P(VALUE obj)
Queries if the object is an instance of rb_cFloat.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.