summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-04 16:03:24 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-05-04 16:03:24 +0000
commitf595d5b0d24d9b0323aba79ae07a6e1c9dbfbe36 (patch)
treea6f751d98db26e466d957576ef3fee9974cbb471 /array.c
parentf001f2f6d584d948b9b321171875ee872048df23 (diff)
* array.c (rb_ary_values_at): new method to replace select(index..).
* hash.c (rb_hash_values_at,env_values_at): ditto. * re.c (match_values_at): ditto. * struct.c (rb_struct_values_at): ditto. * re.c (match_select): add iterator behavior. * ext/curses/curses.c, ext/digest/sha2/sha2.c, ext/iconv/iconv.c, ext/racc/cparse/cparse.c: include "ruby.h" at the top to shut up "_FILE_OFFSET_BITS redefined" warning on Solaris. * class.c (rb_class_protected_instance_methods): now gives warnings to show migration path. The default will be reversed on Jan 2004. * numeric.c (num_step): "1.1.step(1.5,0.1)" to work. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c44
1 files changed, 28 insertions, 16 deletions
diff --git a/array.c b/array.c
index 8deeaf6..adb5113 100644
--- a/array.c
+++ b/array.c
@@ -616,7 +616,7 @@ rb_ary_indexes(argc, argv, ary)
VALUE new_ary;
long i;
- rb_warn("Array#%s is deprecated; use Array#select",
+ rb_warn("Array#%s is deprecated; use Array#values_at",
rb_id2name(rb_frame_last_func()));
new_ary = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
@@ -1160,6 +1160,21 @@ rb_ary_collect_bang(ary)
}
static VALUE
+rb_ary_values_at(argc, argv, ary)
+ int argc;
+ VALUE *argv;
+ VALUE ary;
+{
+ VALUE result = rb_ary_new2(argc);
+ long i;
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(argv[i])));
+ }
+ return result;
+}
+
+static VALUE
rb_ary_select(argc, argv, ary)
int argc;
VALUE *argv;
@@ -1168,21 +1183,17 @@ rb_ary_select(argc, argv, ary)
VALUE result;
long i;
- if (rb_block_given_p()) {
- if (argc > 0) {
- rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
- }
- result = rb_ary_new2(RARRAY(ary)->len);
- for (i = 0; i < RARRAY(ary)->len; i++) {
- if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
- rb_ary_push(result, RARRAY(ary)->ptr[i]);
- }
- }
+ if (!rb_block_given_p()) {
+ rb_warn("Array#select(index..) is deprecated; use Array#values_at");
+ return rb_ary_values_at(argc, argv, ary);
}
- else {
- result = rb_ary_new2(argc);
- for (i=0; i<argc; i++) {
- rb_ary_push(result, rb_ary_entry(ary, NUM2LONG(argv[i])));
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
+ }
+ result = rb_ary_new2(RARRAY(ary)->len);
+ for (i = 0; i < RARRAY(ary)->len; i++) {
+ if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
+ rb_ary_push(result, RARRAY(ary)->ptr[i]);
}
}
return result;
@@ -1954,9 +1965,10 @@ Init_Array()
rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0);
rb_define_method(rb_cArray, "collect", rb_ary_collect, 0);
rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0);
- rb_define_method(rb_cArray, "select", rb_ary_select, -1);
rb_define_method(rb_cArray, "map", rb_ary_collect, 0);
rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0);
+ rb_define_method(rb_cArray, "select", rb_ary_select, -1);
+ rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1);
rb_define_method(rb_cArray, "delete", rb_ary_delete, 1);
rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at_m, 1);
rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0);