summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-12-14 06:50:43 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-12-14 06:50:43 +0000
commit9d228b13deccfdf23f44e2c465f723a2a7b3bcbd (patch)
tree9a4d769804c389b6b03bbfdf65e8e0a03288c8e8 /range.c
parentc18d3740a925e8752c3b93acea6087fb0e03be53 (diff)
19991214
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@587 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/range.c b/range.c
index 8af5b69..b6cda5d 100644
--- a/range.c
+++ b/range.c
@@ -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);