Lines Matching refs:range

3   range.c -
35 rb_raise(rb_eArgError, "bad value for range");
46 range_init(VALUE range, VALUE beg, VALUE end, int exclude_end)
61 SET_EXCL(range, exclude_end);
62 RSTRUCT(range)->as.ary[0] = beg;
63 RSTRUCT(range)->as.ary[1] = end;
69 VALUE range = rb_obj_alloc(rb_cRange);
71 range_init(range, beg, end, exclude_end);
72 return range;
79 * Constructs a range using the given +begin+ and +end+. If the +exclude_end+
85 range_initialize(int argc, VALUE *argv, VALUE range)
91 if (RANGE_EXCL(range) != Qnil) {
94 range_init(range, beg, end, RTEST(flags));
104 * Returns <code>true</code> if the range excludes its end value.
111 range_exclude_end_p(VALUE range)
113 return EXCL(range) ? Qtrue : Qfalse;
117 recursive_equal(VALUE range, VALUE obj, int recur)
120 if (!rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
122 if (!rb_equal(RANGE_END(range), RANGE_END(obj)))
125 if (EXCL(range) != EXCL(obj))
137 * the same #exclude_end? setting as the range.
146 range_eq(VALUE range, VALUE obj)
148 if (range == obj)
153 return rb_exec_recursive_paired(recursive_equal, range, obj, obj);
186 recursive_eql(VALUE range, VALUE obj, int recur)
189 if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
191 if (!rb_eql(RANGE_END(range), RANGE_END(obj)))
194 if (EXCL(range) != EXCL(obj))
205 * and has the same #exclude_end? setting as the range.
214 range_eql(VALUE range, VALUE obj)
216 if (range == obj)
220 return rb_exec_recursive_paired(recursive_eql, range, obj, obj);
224 recursive_hash(VALUE range, VALUE dummy, int recur)
226 st_index_t hash = EXCL(range);
231 v = rb_hash(RANGE_BEG(range));
233 v = rb_hash(RANGE_END(range));
236 hash = rb_hash_uint(hash, EXCL(range) << 24);
246 * Compute a hash-code for this range. Two ranges with equal
252 range_hash(VALUE range)
254 return rb_exec_recursive_outer(recursive_hash, range, 0);
258 range_each_func(VALUE range, VALUE (*func) (VALUE, void *), void *arg)
261 VALUE b = RANGE_BEG(range);
262 VALUE e = RANGE_END(range);
265 if (EXCL(range)) {
325 range_step_size(VALUE range, VALUE args)
327 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
343 return num_interval_step_size(b, e, step, EXCL(range));
353 * Iterates over the range, passing each <code>n</code>th element to the block.
356 * range elements.
360 * range = Xs.new(1)..Xs.new(10)
361 * range.step(2) {|x| puts x}
363 * range.step(3) {|x| puts x}
383 range_step(int argc, VALUE *argv, VALUE range)
387 RETURN_SIZED_ENUMERATOR(range, argc, argv, range_step_size);
389 b = RANGE_BEG(range);
390 e = RANGE_END(range);
411 if (!EXCL(range))
425 args[1] = EXCL(range) ? Qtrue : Qfalse;
430 else if (ruby_float_step(b, e, step, EXCL(range))) {
436 ID op = EXCL(range) ? '<' : idLE;
454 args[1] = EXCL(range) ? Qtrue : Qfalse;
468 range_each_func(range, step_i, args);
471 return range;
514 * By using binary search, finds a value in range which meets the given
515 * condition in O(log n) where n is the size of the range.
518 * a find-any mode. In either case, the elements of the range must be
529 * If x is within the range, this method returns the value x.
549 * the given range and x...y (if any). If there is no value that
563 range_bsearch(VALUE range)
610 RETURN_ENUMERATOR(range, 0, 0); \
611 if (EXCL(range)) high--; \
633 beg = RANGE_BEG(range);
634 end = RANGE_END(range);
654 RETURN_ENUMERATOR(range, 0, 0);
655 if (EXCL(range)) high = rb_funcall(high, '-', 1, INT2FIX(1));
678 return range;
699 * Returns the number of elements in the range. Both the begin and the end of
708 range_size(VALUE range)
710 VALUE b = RANGE_BEG(range), e = RANGE_END(range);
712 return num_interval_step_size(b, e, INT2FIX(1), EXCL(range));
722 * Iterates over the elements of range, passing each in turn to the
725 * The +each+ method can only be used if the begin object of the range
739 range_each(VALUE range)
743 RETURN_SIZED_ENUMERATOR(range, 0, 0, range_size);
745 beg = RANGE_BEG(range);
746 end = RANGE_END(range);
752 if (!EXCL(range))
762 args[1] = EXCL(range) ? Qtrue : Qfalse;
772 args[1] = EXCL(range) ? Qtrue : Qfalse;
780 range_each_func(range, each_i, NULL);
783 return range;
790 * Returns the object that defines the beginning of the range.
796 range_begin(VALUE range)
798 return RANGE_BEG(range);
806 * Returns the object that defines the end of the range.
814 range_end(VALUE range)
816 return RANGE_END(range);
839 * Returns the first object in the range, or an array of the first +n+
847 range_first(int argc, VALUE *argv, VALUE range)
851 if (argc == 0) return RANGE_BEG(range);
856 rb_block_call(range, idEach, 0, 0, first_i, (VALUE)ary);
867 * Returns the last object in the range,
871 * the end of the range even if #exclude_end? is +true+.
880 range_last(int argc, VALUE *argv, VALUE range)
882 if (argc == 0) return RANGE_END(range);
883 return rb_ary_last(argc, argv, rb_Array(range));
892 * Returns the minimum value in the range. Returns +nil+ if the begin
893 * value of the range is larger than the end value.
903 range_min(VALUE range)
909 VALUE b = RANGE_BEG(range);
910 VALUE e = RANGE_END(range);
913 if (c > 0 || (c == 0 && EXCL(range)))
924 * Returns the maximum value in the range. Returns +nil+ if the begin
925 * value of the range larger than the end value.
934 range_max(VALUE range)
936 VALUE e = RANGE_END(range);
939 if (rb_block_given_p() || (EXCL(range) && !nm)) {
943 VALUE b = RANGE_BEG(range);
948 if (EXCL(range)) {
966 rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
971 if (rb_obj_is_kind_of(range, rb_cRange)) {
972 b = RANGE_BEG(range);
973 e = RANGE_END(range);
974 excl = EXCL(range);
977 if (!rb_respond_to(range, id_beg)) return (int)Qfalse;
978 if (!rb_respond_to(range, id_end)) return (int)Qfalse;
979 b = rb_funcall(range, id_beg, 0);
980 e = rb_funcall(range, id_end, 0);
981 excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0));
990 rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
996 if (!rb_range_values(range, &b, &e, &excl))
1027 rb_raise(rb_eRangeError, "%ld..%s%ld out of range",
1037 * Convert this range object to a printable form (using #to_s to convert the
1042 range_to_s(VALUE range)
1046 str = rb_obj_as_string(RANGE_BEG(range));
1047 str2 = rb_obj_as_string(RANGE_END(range));
1049 rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
1057 inspect_range(VALUE range, VALUE dummy, int recur)
1062 return rb_str_new2(EXCL(range) ? "(... ... ...)" : "(... .. ...)");
1064 str = rb_inspect(RANGE_BEG(range));
1065 str2 = rb_inspect(RANGE_END(range));
1067 rb_str_cat(str, "...", EXCL(range) ? 3 : 2);
1078 * Convert this range object to a printable form (using
1085 range_inspect(VALUE range)
1087 return rb_exec_recursive(inspect_range, range, 0);
1094 * Returns <code>true</code> if +obj+ is an element of the range,
1110 range_eqq(VALUE range, VALUE val)
1112 return rb_funcall(range, rb_intern("include?"), 1, val);
1122 * the range, <code>false</code> otherwise. If begin and end are
1131 range_include(VALUE range, VALUE val)
1133 VALUE beg = RANGE_BEG(range);
1134 VALUE end = RANGE_END(range);
1143 if (EXCL(range)) {
1167 if (!EXCL(range) && v == e) return Qtrue;
1183 * the range.
1194 range_cover(VALUE range, VALUE val)
1198 beg = RANGE_BEG(range);
1199 end = RANGE_END(range);
1201 if (EXCL(range)) {
1214 range_dumper(VALUE range)
1221 rb_ivar_set(v, id_excl, RANGE_EXCL(range));
1222 rb_ivar_set(v, id_beg, RANGE_BEG(range));
1223 rb_ivar_set(v, id_end, RANGE_END(range));
1228 range_loader(VALUE range, VALUE obj)
1231 rb_raise(rb_eTypeError, "not a dumped range object");
1234 RSTRUCT(range)->as.ary[0] = rb_ivar_get(obj, id_beg);
1235 RSTRUCT(range)->as.ary[1] = rb_ivar_get(obj, id_end);
1236 RSTRUCT(range)->as.ary[2] = rb_ivar_get(obj, id_excl);
1237 return range;
1266 * Methods that treat the range as a sequence (#each and methods inherited
1297 * An example of using <code>Xs</code> to construct a range: