mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
991207
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@577 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
dee96209bf
commit
c18d3740a9
15 changed files with 172 additions and 128 deletions
21
range.c
21
range.c
|
@ -262,6 +262,25 @@ range_inspect(range)
|
|||
return str;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
length_i(i, length)
|
||||
VALUE i;
|
||||
int *length;
|
||||
{
|
||||
(*length)++;
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_length_by_each(obj)
|
||||
VALUE obj;
|
||||
{
|
||||
int length = 0;
|
||||
|
||||
rb_iterate(rb_each, obj, length_i, (VALUE)&length);
|
||||
return INT2FIX(length);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
range_length(range)
|
||||
VALUE range;
|
||||
|
@ -284,7 +303,7 @@ range_length(range)
|
|||
}
|
||||
}
|
||||
if (!rb_obj_is_kind_of(beg, rb_cNumeric)) {
|
||||
return rb_enum_length(range);
|
||||
return rb_length_by_each(range);
|
||||
}
|
||||
size = rb_funcall(end, '-', 1, beg);
|
||||
if (!EXCL(range)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue