mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
* range.c (range_each): should honor to_str conversion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24571 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a5aefa661e
commit
554786aedc
3 changed files with 22 additions and 11 deletions
26
range.c
26
range.c
|
@ -436,19 +436,23 @@ range_each(VALUE range)
|
|||
rb_yield(LONG2FIX(i));
|
||||
}
|
||||
}
|
||||
else if (TYPE(beg) == T_STRING) {
|
||||
VALUE args[2];
|
||||
|
||||
args[0] = end;
|
||||
args[1] = EXCL(range) ? Qtrue : Qfalse;
|
||||
rb_block_call(beg, rb_intern("upto"), 2, args, rb_yield, 0);
|
||||
}
|
||||
else {
|
||||
if (!rb_respond_to(beg, id_succ)) {
|
||||
rb_raise(rb_eTypeError, "can't iterate from %s",
|
||||
rb_obj_classname(beg));
|
||||
VALUE tmp = rb_check_string_type(beg);
|
||||
|
||||
if (!NIL_P(tmp)) {
|
||||
VALUE args[2];
|
||||
|
||||
args[0] = end;
|
||||
args[1] = EXCL(range) ? Qtrue : Qfalse;
|
||||
rb_block_call(tmp, rb_intern("upto"), 2, args, rb_yield, 0);
|
||||
}
|
||||
else {
|
||||
if (!rb_respond_to(beg, id_succ)) {
|
||||
rb_raise(rb_eTypeError, "can't iterate from %s",
|
||||
rb_obj_classname(beg));
|
||||
}
|
||||
range_each_func(range, each_i, NULL);
|
||||
}
|
||||
range_each_func(range, each_i, NULL);
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue