summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-02 04:49:46 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-06-02 04:49:46 +0000
commit6125313d69c158b423d1f4aff2e206cfd43a036a (patch)
treea1a78a9425305557dcff6569806876989c9098c3 /array.c
parentf5a7f85917abed4d64ad908a4837e0db0499c951 (diff)
* array.c (push_values_at): Array#values_at should work with
ranges too. * range.c (rb_range_beg_len): length calculation was wrong. * eval.c (rb_call): should set T_ICLASS in the frame->last_class. [ruby-core:01110] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/array.c b/array.c
index 7359c05..e0b5af8 100644
--- a/array.c
+++ b/array.c
@@ -1179,6 +1179,31 @@ rb_ary_collect_bang(ary)
return ary;
}
+static void
+push_values_at(result, ary, arg)
+ VALUE result, ary, arg;
+{
+ long beg, len, i;
+
+ if (FIXNUM_P(arg)) {
+ rb_ary_push(result, rb_ary_entry(ary, FIX2LONG(arg)));
+ return;
+ }
+ /* check if idx is Range */
+ switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
+ case Qfalse:
+ break;
+ case Qnil:
+ return;
+ default:
+ for (i=0; i<len; i++) {
+ rb_ary_push(result, rb_ary_entry(ary, i+beg));
+ }
+ return;
+ }
+ rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(arg)));
+}
+
static VALUE
rb_ary_values_at(argc, argv, ary)
int argc;
@@ -1189,7 +1214,7 @@ rb_ary_values_at(argc, argv, ary)
long i;
for (i=0; i<argc; i++) {
- rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(argv[i])));
+ push_values_at(result, ary, argv[i]);
}
return result;
}