1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 1999-12-14 06:50:43 +00:00
parent c18d3740a9
commit 9d228b13de
34 changed files with 649 additions and 508 deletions

14
range.c
View file

@ -138,6 +138,16 @@ range_each(range)
else if (TYPE(b) == T_STRING) {
rb_str_upto(b, e, EXCL(range));
}
else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
b = rb_Integer(b);
e = rb_Integer(e);
if (!EXCL(range)) e = rb_funcall(e, '+', 1, INT2FIX(1));
while (RTEST(rb_funcall(b, '<', 1, e))) {
rb_yield(b);
b = rb_funcall(b, '+', 1, INT2FIX(1));
}
}
else { /* generic each */
VALUE v = b;
ID succ = rb_intern("succ");
@ -286,7 +296,7 @@ range_length(range)
VALUE range;
{
VALUE beg, end;
VALUE size;
long size;
beg = rb_ivar_get(range, id_beg);
end = rb_ivar_get(range, id_end);
@ -302,7 +312,7 @@ range_length(range)
return INT2NUM(NUM2LONG(end) - NUM2LONG(beg) + 1);
}
}
if (!rb_obj_is_kind_of(beg, rb_cNumeric)) {
if (!rb_obj_is_kind_of(beg, rb_cInteger)) {
return rb_length_by_each(range);
}
size = rb_funcall(end, '-', 1, beg);