summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-09-16 09:40:33 +0000
commit9e3d9a2a009d2a0281802a84e1c5cc1c887edc71 (patch)
treeea994af7deeef43977f60a9ab26131e8cd90a9a0 /range.c
parent69a3aaf154948d653fa3653cd2b3c3b3af979769 (diff)
1.4.1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/range.c b/range.c
index d37dfaa..b1925e9 100644
--- a/range.c
+++ b/range.c
@@ -134,14 +134,28 @@ range_each(range)
rb_yield(INT2NUM(i));
}
}
- else { /* generic each */
+ else if (TYPE(b) == T_STRING) {
+ rb_str_upto(b, e, EXCL(range));
+ }
+ else { /* generic each */
VALUE v = b;
- ID le = EXCL(range)?'<':rb_intern("<=");
ID succ = rb_intern("succ");
- while (rb_funcall(v, le, 1, e)) {
- rb_yield(v);
- v = rb_funcall(v, succ, 0, 0);
+ if (EXCL(range)) {
+ while (RTEST(rb_funcall(v, '<', 1, e))) {
+ if (rb_equal(v, e)) break;
+ rb_yield(v);
+ v = rb_funcall(v, succ, 0, 0);
+ }
+ }
+ else {
+ ID le = rb_intern("<=");
+
+ while (RTEST(rb_funcall(v, le, 1, e))) {
+ rb_yield(v);
+ if (rb_equal(v, e)) break;
+ v = rb_funcall(v, succ, 0, 0);
+ }
}
}