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;
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))
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)));
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));
205 return rb_cmpint(r, a, 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));
272range_hash(
VALUE range)
274 st_index_t hash = EXCL(range);
278 v = rb_hash(RANGE_BEG(range));
280 v = rb_hash(RANGE_END(range));
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;
299 v = rb_funcallv(v, id_succ, 0, 0);
303 while ((c = r_less(v, e)) <= 0) {
304 if ((*func)(v, arg))
break;
306 v = rb_funcallv(v, id_succ, 0, 0);
312step_i_iter(
VALUE arg)
317 iter[0] -=
INT2FIX(1) & ~FIXNUM_FLAG;
322 if (iter[0] !=
INT2FIX(0))
return false;
330 if (step_i_iter(arg)) {
339 if (step_i_iter(arg)) {
346discrete_object_p(
VALUE obj)
352linear_object_p(
VALUE obj)
369check_step_domain(
VALUE step)
376 cmp = rb_cmpint(rb_funcallv(step, idCmp, 1, &zero), step, zero);
378 rb_raise(rb_eArgError,
"step can't be negative");
381 rb_raise(rb_eArgError,
"step can't be 0");
389 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
396 return ruby_num_interval_step_size(b, e, step, EXCL(range));
441 VALUE b, e, step, tmp;
443 b = RANGE_BEG(range);
444 e = RANGE_END(range);
452 rb_raise(rb_eArgError,
"step can't be 0");
457 if ((b_num_p && (
NIL_P(e) || e_num_p)) || (
NIL_P(b) && e_num_p)) {
458 return rb_arith_seq_new(range,
ID2SYM(rb_frame_this_func()), argc, argv,
459 range_step_size, b, e, step, EXCL(range));
465 step = check_step_domain(step);
476 for (;; b = rb_big_plus(b, 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)) {
536 range_each_func(range, step_i, (
VALUE)iter);
538 for (;; b = rb_funcallv(b, id_succ, 0, 0))
539 step_i(b, (
VALUE)iter);
575 return range_step(1, &step, range);
578#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
585int64_as_double_to_num(int64_t i)
587 union int64_double convert;
599double_as_int64(
double d)
601 union int64_double convert;
603 return d < 0 ? -convert.i : convert.i;
618 return RTEST(is_int) && !UNDEF_P(is_int);
622bsearch_integer_range(
VALUE beg,
VALUE end,
int excl)
627#define BSEARCH_CHECK(expr) \
629 VALUE val = (expr); \
630 VALUE v = rb_yield(val); \
632 if (v == INT2FIX(0)) return val; \
633 smaller = (SIGNED_VALUE)v < 0; \
635 else if (v == Qtrue) { \
639 else if (!RTEST(v)) { \
642 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
643 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
644 if (!cmp) return val; \
648 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
649 " (must be numeric, true, false or nil)", \
671 rb_cmpint(
rb_funcall(low, id_cmp, 1, mid), low, mid) < 0) {
694range_bsearch(
VALUE range)
719#define BSEARCH(conv, excl) \
721 RETURN_ENUMERATOR(range, 0, 0); \
722 if (!(excl)) high++; \
724 while (low + 1 < high) { \
725 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
726 : (low + high) / 2; \
727 BSEARCH_CHECK(conv(mid)); \
738#define BSEARCH_FIXNUM(beg, end, excl) \
740 long low = FIX2LONG(beg); \
741 long high = FIX2LONG(end); \
743 BSEARCH(INT2FIX, (excl)); \
746 beg = RANGE_BEG(range);
747 end = RANGE_END(range);
750 BSEARCH_FIXNUM(beg, end, EXCL(range));
752#if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T)
757 BSEARCH(int64_as_double_to_num, EXCL(range));
760 else if (is_integer_p(beg) && is_integer_p(end)) {
762 return bsearch_integer_range(beg, end, EXCL(range));
764 else if (is_integer_p(beg) &&
NIL_P(end)) {
772 BSEARCH_FIXNUM(beg, mid,
false);
775 return bsearch_integer_range(beg, mid,
false);
782 else if (
NIL_P(beg) && is_integer_p(end)) {
790 BSEARCH_FIXNUM(mid, end,
false);
793 return bsearch_integer_range(mid, end,
false);
816 return each_i(rb_str_intern(v), arg);
836range_size(
VALUE range)
838 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
841 return ruby_num_interval_step_size(b, e,
INT2FIX(1), EXCL(range));
870range_to_a(
VALUE range)
872 if (
NIL_P(RANGE_END(range))) {
873 rb_raise(
rb_eRangeError,
"cannot convert endless range to an array");
881 return range_size(range);
886range_each_bignum_endless(
VALUE beg)
888 for (;; beg = rb_big_plus(beg,
INT2FIX(1))) {
896range_each_fixnum_endless(
VALUE beg)
909 long lim =
FIX2LONG(end) + !EXCL(range);
910 for (
long i =
FIX2LONG(beg); i < lim; i++) {
934range_each(
VALUE range)
941 beg = RANGE_BEG(range);
942 end = RANGE_END(range);
945 range_each_fixnum_endless(beg);
948 return range_each_fixnum_loop(beg, end, range);
957 if (
NIL_P(end)) range_each_fixnum_endless(beg);
958 if (
FIXNUM_P(end))
return range_each_fixnum_loop(beg, end, range);
961 if (
NIL_P(end)) range_each_bignum_endless(beg);
977 while (rb_big_cmp(beg, end) ==
INT2FIX(-1)) {
979 beg = rb_big_plus(beg,
INT2FIX(1));
984 while ((c = rb_big_cmp(beg, end)) !=
INT2FIX(1)) {
987 beg = rb_big_plus(beg,
INT2FIX(1));
995 rb_str_upto_endless_each(beg, sym_each_i, 0);
998 rb_str_upto_each(beg,
rb_sym2str(end), EXCL(range), sym_each_i, 0);
1006 rb_str_upto_each(tmp, end, EXCL(range), each_i, 0);
1009 rb_str_upto_endless_each(tmp, each_i, 0);
1013 if (!discrete_object_p(beg)) {
1018 range_each_func(range, each_i, 0);
1020 for (;; beg = rb_funcallv(beg, id_succ, 0, 0))
1029range_reverse_each_bignum_beginless(
VALUE end)
1033 for (;; end = rb_big_minus(end,
INT2FIX(1))) {
1040range_reverse_each_bignum(
VALUE beg,
VALUE end)
1045 while ((c = rb_big_cmp(beg, end)) !=
INT2FIX(1)) {
1048 end = rb_big_minus(end,
INT2FIX(1));
1053range_reverse_each_positive_bignum_section(
VALUE beg,
VALUE end)
1063 range_reverse_each_bignum(beg, end);
1067range_reverse_each_fixnum_section(
VALUE beg,
VALUE end)
1085 for (
long i = e; i >= b; --i) {
1091range_reverse_each_negative_bignum_section(
VALUE beg,
VALUE end)
1100 range_reverse_each_bignum_beginless(end);
1105 range_reverse_each_bignum(beg, end);
1128range_reverse_each(
VALUE range)
1132 VALUE beg = RANGE_BEG(range);
1133 VALUE end = RANGE_END(range);
1134 int excl = EXCL(range);
1145 end = rb_int_minus(end,
INT2FIX(1));
1148 range_reverse_each_fixnum_section(beg, end);
1152 end = rb_int_minus(end,
INT2FIX(1));
1154 range_reverse_each_positive_bignum_section(beg, end);
1155 range_reverse_each_fixnum_section(beg, end);
1156 range_reverse_each_negative_bignum_section(beg, end);
1178range_begin(
VALUE range)
1180 return RANGE_BEG(range);
1199range_end(
VALUE range)
1201 return RANGE_END(range);
1214 rb_ary_push(ary[1], i);
1243range_first(
int argc,
VALUE *argv,
VALUE range)
1247 if (
NIL_P(RANGE_BEG(range))) {
1248 rb_raise(
rb_eRangeError,
"cannot get the first element of beginless range");
1250 if (argc == 0)
return RANGE_BEG(range);
1261rb_int_range_last(
int argc,
VALUE *argv,
VALUE range)
1271 b = RANGE_BEG(range);
1272 e = RANGE_END(range);
1277 len_1 = rb_int_minus(e, b);
1279 e = rb_int_minus(e, ONE);
1283 len = rb_int_plus(len_1, ONE);
1286 if (FIXNUM_ZERO_P(
len) || rb_num_negative_p(
len)) {
1287 return rb_ary_new_capa(0);
1293 rb_raise(rb_eArgError,
"negative array size");
1302 ary = rb_ary_new_capa(n);
1303 b = rb_int_minus(e, nv);
1305 b = rb_int_plus(b, ONE);
1306 rb_ary_push(ary, b);
1349range_last(
int argc,
VALUE *argv,
VALUE range)
1353 if (
NIL_P(RANGE_END(range))) {
1354 rb_raise(
rb_eRangeError,
"cannot get the last element of endless range");
1356 if (argc == 0)
return RANGE_END(range);
1358 b = RANGE_BEG(range);
1359 e = RANGE_END(range);
1361 RB_LIKELY(rb_method_basic_definition_p(
rb_cRange, idEach))) {
1362 return rb_int_range_last(argc, argv, range);
1364 return rb_ary_last(argc, argv,
rb_Array(range));
1452 if (
NIL_P(RANGE_BEG(range))) {
1453 rb_raise(
rb_eRangeError,
"cannot get the minimum of beginless range");
1457 if (
NIL_P(RANGE_END(range))) {
1458 rb_raise(
rb_eRangeError,
"cannot get the minimum of endless range with custom comparison method");
1462 else if (argc != 0) {
1463 return range_first(argc, argv, range);
1466 VALUE b = RANGE_BEG(range);
1467 VALUE e = RANGE_END(range);
1468 int c =
NIL_P(e) ? -1 : OPTIMIZED_CMP(b, e);
1470 if (c > 0 || (c == 0 && EXCL(range)))
1560 VALUE e = RANGE_END(range);
1563 if (
NIL_P(RANGE_END(range))) {
1564 rb_raise(
rb_eRangeError,
"cannot get the maximum of endless range");
1567 VALUE b = RANGE_BEG(range);
1571 rb_raise(
rb_eRangeError,
"cannot get the maximum of beginless range with custom comparison method");
1576 int c =
NIL_P(b) ? -1 : OPTIMIZED_CMP(b, e);
1582 rb_raise(
rb_eTypeError,
"cannot exclude non Integer end value");
1584 if (c == 0)
return Qnil;
1586 rb_raise(
rb_eTypeError,
"cannot exclude end value with non Integer begin value");
1644range_minmax(
VALUE range)
1649 return rb_assoc_new(
1662 b = RANGE_BEG(range);
1663 e = RANGE_END(range);
1672 if (UNDEF_P(b))
return (
int)
Qfalse;
1674 if (UNDEF_P(e))
return (
int)
Qfalse;
1676 if (UNDEF_P(x))
return (
int)
Qfalse;
1708rb_range_component_beg_len(
VALUE b,
VALUE e,
int excl,
1709 long *begp,
long *lenp,
long len,
int err)
1715 if (
NIL_P(e)) excl = 0;
1725 if (err == 0 || err == 2) {
1752 VALUE res = rb_range_component_beg_len(b, e, excl, begp, lenp,
len, err);
1753 if (
NIL_P(res) && err) {
1782range_to_s(
VALUE range)
1786 str = rb_obj_as_string(RANGE_BEG(range));
1787 str2 = rb_obj_as_string(RANGE_END(range));
1788 str = rb_str_dup(str);
1789 rb_str_cat(str,
"...", EXCL(range) ? 3 : 2);
1796inspect_range(
VALUE range,
VALUE dummy,
int recur)
1801 return rb_str_new2(EXCL(range) ?
"(... ... ...)" :
"(... .. ...)");
1803 if (!
NIL_P(RANGE_BEG(range)) ||
NIL_P(RANGE_END(range))) {
1804 str = rb_str_dup(
rb_inspect(RANGE_BEG(range)));
1809 rb_str_cat(str,
"...", EXCL(range) ? 3 : 2);
1810 if (
NIL_P(RANGE_BEG(range)) || !
NIL_P(RANGE_END(range))) {
1841range_inspect(
VALUE range)
1891 return r_cover_p(range, RANGE_BEG(range), RANGE_END(range), val);
1927 VALUE ret = range_include_internal(range, val);
1928 if (!UNDEF_P(ret))
return ret;
1949 if (linear_object_p(val))
return Qtrue;
1953 rb_raise(
rb_eTypeError,
"cannot determine inclusion in beginless/endless ranges");
1960range_include_internal(
VALUE range,
VALUE val)
1962 VALUE beg = RANGE_BEG(range);
1963 VALUE end = RANGE_END(range);
1965 linear_object_p(beg) || linear_object_p(end);
1967 if (nv || range_integer_edge_p(beg, end)) {
1968 return r_cover_p(range, beg, end, val);
1970 else if (range_string_range_p(beg, end)) {
1971 return rb_str_include_range_p(beg, end, val, RANGE_EXCL(range));
1974 return range_include_fallback(beg, end, val);
2111 beg = RANGE_BEG(range);
2112 end = RANGE_END(range);
2115 return RBOOL(r_cover_range_p(range, beg, end, val));
2117 return r_cover_p(range, beg, end, val);
2123 return rb_funcallv(r, rb_intern(
"max"), 0, 0);
2129 VALUE val_beg, val_end, val_max;
2132 val_beg = RANGE_BEG(val);
2133 val_end = RANGE_END(val);
2135 if (!
NIL_P(end) &&
NIL_P(val_end))
return FALSE;
2136 if (!
NIL_P(beg) &&
NIL_P(val_beg))
return FALSE;
2137 if (!
NIL_P(val_beg) && !
NIL_P(val_end) && r_less(val_beg, val_end) > (EXCL(val) ? -1 : 0)) return FALSE;
2138 if (!
NIL_P(val_beg) && !r_cover_p(range, beg, end, val_beg))
return FALSE;
2143 if (
NIL_P(r_cmp_end))
return FALSE;
2144 cmp_end = rb_cmpint(r_cmp_end, end, val_end);
2147 cmp_end = r_less(end, val_end);
2151 if (EXCL(range) == EXCL(val)) {
2152 return cmp_end >= 0;
2154 else if (EXCL(range)) {
2157 else if (cmp_end >= 0) {
2162 if (
NIL_P(val_max))
return FALSE;
2164 return r_less(end, val_max) >= 0;
2170 if (
NIL_P(beg) || r_less(beg, val) <= 0) {
2171 int excl = EXCL(range);
2172 if (
NIL_P(end) || r_less(val, end) <= -excl)
2179range_dumper(
VALUE range)
2192 VALUE beg, end, excl;
2194 if (!RB_TYPE_P(obj,
T_OBJECT) ||
RBASIC(obj)->klass != rb_cObject) {
2198 range_modify(range);
2203 range_init(range, beg, end, RBOOL(
RTEST(excl)));
2209range_alloc(
VALUE klass)
2248range_count(
int argc,
VALUE *argv,
VALUE range)
2261 VALUE beg = RANGE_BEG(range), end = RANGE_END(range);
2268 if (is_integer_p(beg)) {
2269 VALUE size = range_size(range);
2279empty_region_p(
VALUE beg,
VALUE end,
int excl)
2281 if (
NIL_P(beg))
return false;
2282 if (
NIL_P(end))
return false;
2283 int less = r_less(beg, end);
2285 if (less > 0)
return true;
2286 if (excl && less == 0)
return true;
2362 rb_raise(
rb_eTypeError,
"wrong argument type %"PRIsVALUE
" (expected Range)",
2366 VALUE self_beg = RANGE_BEG(range);
2367 VALUE self_end = RANGE_END(range);
2368 int self_excl = EXCL(range);
2369 VALUE other_beg = RANGE_BEG(other);
2370 VALUE other_end = RANGE_END(other);
2371 int other_excl = EXCL(other);
2373 if (empty_region_p(self_beg, other_end, other_excl))
return Qfalse;
2374 if (empty_region_p(other_beg, self_end, self_excl))
return Qfalse;
2380 if (rb_cmpint(cmp, self_beg, other_beg) == 0)
return Qtrue;
2382 else if (
NIL_P(self_beg) &&
NIL_P(other_beg)) {
2384 return RBOOL(!
NIL_P(cmp));
2387 if (empty_region_p(self_beg, self_end, self_excl))
return Qfalse;
2388 if (empty_region_p(other_beg, other_end, other_excl))
return Qfalse;
2636 "Range", rb_cObject, range_alloc,
2637 "begin",
"end",
"excl", NULL);
#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.
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.
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 FIXNUM_MIN
Old name of RUBY_FIXNUM_MIN.
#define FLONUM_P
Old name of RB_FLONUM_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define ST2FIX
Old name of RB_ST2FIX.
#define FIXNUM_MAX
Old name of RUBY_FIXNUM_MAX.
#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_iter_break(void)
Breaks from a block.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_cTime
Time class.
VALUE rb_Float(VALUE val)
This is the logic behind Kernel#Float.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_mEnumerable
Enumerable module.
int rb_eql(VALUE lhs, VALUE rhs)
Checks for equality of the passed objects, in terms of Object#eql?.
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_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_cRange
Range class.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given 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.
VALUE rb_to_int(VALUE val)
Identical to rb_check_to_int(), except it raises in case of conversion mismatch.
#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_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
#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.
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.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
st_index_t rb_hash_start(st_index_t i)
Starts a series of hashing.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
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.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
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().
VALUE rb_sym2str(VALUE id)
Identical to rb_id2str(), except it takes an instance of rb_cSymbol rather than an ID.
int len
Length of the buffer.
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
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.
VALUE rb_block_call(VALUE q, ID w, int e, const VALUE *r, type *t, VALUE y)
Call a method with a block.
VALUE rb_rescue2(type *q, VALUE w, type *e, VALUE r,...)
An equivalent of rescue clause.
#define RBIMPL_ATTR_NORETURN()
Wraps (or simulates) [[noreturn]]
#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.
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 bool rb_integer_type_p(VALUE obj)
Queries if the object is an instance of rb_cInteger.