summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-07 15:34:31 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-07 15:34:31 +0000
commit9481face427a93e1a557ecd980ec82f5d04da8d5 (patch)
tree62cdfef0f5cf342039ea74934348a4de34d77007 /range.c
parenta4c37a4b7fb14c1eb81cbd3226761c522f3a49bc (diff)
* parse.y (value_expr0): class and module statements should not be
warned for "void value expression". [ruby-talk:72989] * gc.c (add_final): should determine type by respond_to? * gc.c (define_final): ditto. * io.c (rb_io_ctl): should not depend on respond_to? * range.c (range_step): rb_check_string_type(). * process.c (proc_setgroups): new functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3918 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c57
1 files changed, 31 insertions, 26 deletions
diff --git a/range.c b/range.c
index b7ef175..da8eeda 100644
--- a/range.c
+++ b/range.c
@@ -257,36 +257,41 @@ range_step(argc, argv, range)
rb_yield(LONG2NUM(i));
}
}
- else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
- ID c = rb_intern(EXCL(range) ? "<" : "<=");
-
- if (rb_equal(step, INT2FIX(0))) rb_raise(rb_eArgError, "step can't be 0");
- while (RTEST(rb_funcall(b, c, 1, e))) {
- rb_yield(b);
- b = rb_funcall(b, '+', 1, step);
- }
- }
- else if (TYPE(b) == T_STRING) {
- VALUE args[5];
- long iter[2];
-
- if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
- args[0] = b; args[1] = e; args[2] = range;
- iter[0] = 1; iter[1] = unit;
- rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
- }
else {
- long args[2];
+ VALUE tmp = rb_check_string_type(b);
- if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
- if (!rb_respond_to(b, id_succ)) {
- rb_raise(rb_eTypeError, "cannot iterate from %s",
- rb_obj_classname(b));
+ if (!NIL_P(tmp)) {
+ VALUE args[5];
+ long iter[2];
+
+ b = tmp;
+ if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
+ args[0] = b; args[1] = e; args[2] = range;
+ iter[0] = 1; iter[1] = unit;
+ rb_iterate((VALUE(*)_((VALUE)))str_step, (VALUE)args, step_i, (VALUE)iter);
+ }
+ else if (rb_obj_is_kind_of(b, rb_cNumeric)) {
+ ID c = rb_intern(EXCL(range) ? "<" : "<=");
+
+ if (rb_equal(step, INT2FIX(0))) rb_raise(rb_eArgError, "step can't be 0");
+ while (RTEST(rb_funcall(b, c, 1, e))) {
+ rb_yield(b);
+ b = rb_funcall(b, '+', 1, step);
+ }
}
+ else {
+ long args[2];
+
+ if (unit == 0) rb_raise(rb_eArgError, "step can't be 0");
+ if (!rb_respond_to(b, id_succ)) {
+ rb_raise(rb_eTypeError, "cannot iterate from %s",
+ rb_obj_classname(b));
+ }
- args[0] = 1;
- args[1] = unit;
- range_each_func(range, step_i, b, e, args);
+ args[0] = 1;
+ args[1] = unit;
+ range_each_func(range, step_i, b, e, args);
+ }
}
return range;
}