summaryrefslogtreecommitdiff
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
parentf001f2f6d584d948b9b321171875ee872048df23 (diff)
downloadruby-f595d5b0d24d9b0323aba79ae07a6e1c9dbfbe36.tar.gz
* 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
-rw-r--r--ChangeLog29
-rw-r--r--array.c44
-rw-r--r--class.c29
-rw-r--r--ext/curses/curses.c3
-rw-r--r--ext/digest/sha2/sha2.c2
-rw-r--r--ext/iconv/iconv.c2
-rw-r--r--ext/racc/cparse/cparse.c2
-rw-r--r--hash.c95
-rw-r--r--numeric.c2
-rw-r--r--object.c61
-rw-r--r--re.c31
-rw-r--r--struct.c39
12 files changed, 241 insertions, 98 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b20e1160b..036f198a7d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Mon May 5 00:46:10 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * 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.
+
Sun May 4 19:08:53 2003 Tadayoshi Funaba <tadf@dotrb.org>
* lib/date/format.rb: synchronized with date2 3.3.2.
@@ -10,10 +22,23 @@ Sun May 4 15:06:37 2003 Minero Aoki <aamine@loveruby.net>
* lib/net/pop.rb: APOP did not work. [ruby-dev:20149]
-Sat May 3 00:58:53 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+Sat May 3 21:14:29 2003 Johan Holmberg <holmberg@iar.se>
+
+ * 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.
+
+Sat May 3 11:00:12 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* class.c (rb_class_protected_instance_methods): now gives
- warnings to show migration path.
+ 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.
+
+Sat May 3 00:58:53 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * object.c (rb_obj_methods): now accepts recurse parameter.
* lib/delegate.rb (Delegator::initialize): instance_methods
etc. now recurse by default. need to specify false.
diff --git a/array.c b/array.c
index 8deeaf6ac7..adb511311e 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);
diff --git a/class.c b/class.c
index be2be7e5ae..c0d7c1ed5f 100644
--- a/class.c
+++ b/class.c
@@ -564,8 +564,11 @@ rb_class_instance_methods(argc, argv, mod)
rb_scan_args(argc, argv, "01", &recur);
if (argc == 0) {
- rb_warn("instance_methods() default to true; specify false explicitly");
+#if RUBY_RELEASE_CODE < 20040101
+ rb_warn("instance_methods parameter will default to 'true' in Jan 2004");
+#else
recur = Qtrue;
+#endif
}
return method_list(mod, RTEST(recur), ins_methods_i);
}
@@ -580,8 +583,11 @@ rb_class_protected_instance_methods(argc, argv, mod)
rb_scan_args(argc, argv, "01", &recur);
if (argc == 0) {
- rb_warn("protected_instance_methods() default to true; specify false explicitly");
+#if RUBY_RELEASE_CODE < 20040101
+ rb_warn("protected_instance_methods parameter will default to 'true' in Jan 2004");
+#else
recur = Qtrue;
+#endif
}
if (argc == 0) recur = Qtrue;
return method_list(mod, RTEST(recur), ins_methods_prot_i);
@@ -597,8 +603,11 @@ rb_class_private_instance_methods(argc, argv, mod)
rb_scan_args(argc, argv, "01", &recur);
if (argc == 0) {
- rb_warn("private_instance_methods() default to true; specify false explicitly");
+#if RUBY_RELEASE_CODE < 20040101
+ rb_warn("private_instance_methods parameter will default to 'true' in Jan 2004");
+#else
recur = Qtrue;
+#endif
}
if (argc == 0) recur = Qtrue;
return method_list(mod, RTEST(recur), ins_methods_priv_i);
@@ -614,8 +623,13 @@ rb_class_public_instance_methods(argc, argv, mod)
rb_scan_args(argc, argv, "01", &recur);
if (argc == 0) {
- rb_warn("public_instance_methods() default to true; specify false explicitly");
+#if RUBY_RELEASE_CODE < 20040101
+ rb_warn("instance_methods parameter will default to 'true' in Jan 2004");
+#else
recur = Qtrue;
+#endif
+ rb_warn("public_instance_methods parameter will default to 'true' in Jan 2004");
+ /* recur = Qtrue; */
}
if (argc == 0) recur = Qtrue;
return method_list(mod, RTEST(recur), ins_methods_pub_i);
@@ -632,8 +646,11 @@ rb_obj_singleton_methods(argc, argv, obj)
rb_scan_args(argc, argv, "01", &all);
if (argc == 0) {
- rb_warn("singleton_methods() default to true; specify false explicitly");
- all = Qtrue;
+#if RUBY_RELEASE_CODE < 20040101
+ rb_warn("singleton_methods parameter will default to 'true' in Jan 2004");
+#else
+ recur = Qtrue;
+#endif
}
klass = CLASS_OF(obj);
list = st_init_numtable();
diff --git a/ext/curses/curses.c b/ext/curses/curses.c
index a666cce897..d2263ef007 100644
--- a/ext/curses/curses.c
+++ b/ext/curses/curses.c
@@ -13,6 +13,8 @@
* - Takaaki Tateishi (ttate@kt.jaist.ac.jp)
*/
+#include "ruby.h"
+
#if defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
@@ -46,7 +48,6 @@
#endif
#include <stdio.h>
-#include "ruby.h"
#include "rubyio.h"
static VALUE mCurses;
diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c
index a3c3258082..31b5ff1690 100644
--- a/ext/digest/sha2/sha2.c
+++ b/ext/digest/sha2/sha2.c
@@ -36,10 +36,10 @@
/* $RoughId: sha2.c,v 1.3 2002/02/26 22:03:36 knu Exp $ */
/* $Id$ */
+#include "sha2.h"
#include <stdio.h>
#include <string.h> /* memcpy()/memset() or bcopy()/bzero() */
#include <assert.h> /* assert() */
-#include "sha2.h"
/*
* ASSERT NOTE:
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 098ffb0cfc..e9f2687858 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -32,10 +32,10 @@ Which coding systems are available, it depends on the platform.
=end
*/
+#include "ruby.h"
#include <errno.h>
#include <iconv.h>
#include <assert.h>
-#include "ruby.h"
#include "intern.h"
/* Invalid value for iconv_t is -1 but 0 for VALUE, I hope VALUE is
diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c
index 6ed6293dee..3d75cc9ca7 100644
--- a/ext/racc/cparse/cparse.c
+++ b/ext/racc/cparse/cparse.c
@@ -11,8 +11,8 @@
*/
-#include <stdio.h>
#include "ruby.h"
+#include <stdio.h>
/* -----------------------------------------------------------------------
diff --git a/hash.c b/hash.c
index d07530a834..e5aa6cf109 100644
--- a/hash.c
+++ b/hash.c
@@ -388,7 +388,7 @@ rb_hash_indexes(argc, argv, hash)
VALUE indexes;
int i;
- rb_warn("Hash#%s is deprecated; use Hash#select",
+ rb_warn("Hash#%s is deprecated; use Hash#values_at",
rb_id2name(rb_frame_last_func()));
indexes = rb_ary_new2(argc);
for (i=0; i<argc; i++) {
@@ -509,7 +509,7 @@ select_i(key, value, result)
}
VALUE
-rb_hash_select(argc, argv, hash)
+rb_hash_values_at(argc, argv, hash)
int argc;
VALUE *argv;
VALUE hash;
@@ -517,17 +517,30 @@ rb_hash_select(argc, argv, hash)
VALUE result = rb_ary_new();
long i;
- if (rb_block_given_p()) {
- if (argc > 0) {
- rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
- }
- rb_hash_foreach(hash, select_i, result);
+ for (i=0; i<argc; i++) {
+ rb_ary_push(result, rb_hash_aref(hash, argv[i]));
}
- else {
- for (i=0; i<argc; i++) {
- rb_ary_push(result, rb_hash_aref(hash, argv[i]));
- }
+ return result;
+}
+
+VALUE
+rb_hash_select(argc, argv, hash)
+ int argc;
+ VALUE *argv;
+ VALUE hash;
+{
+ VALUE result;
+ long i;
+
+ if (!rb_block_given_p()) {
+ rb_warn("Hash#select(key..) is deprecated; use Hash#values_at");
+ return rb_hash_values_at(argc, argv, hash);
}
+ result = rb_ary_new();
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
+ }
+ rb_hash_foreach(hash, select_i, result);
return result;
}
@@ -1363,38 +1376,50 @@ env_delete_if()
}
static VALUE
-env_select(argc, argv)
+env_values_at(argc, argv)
int argc;
VALUE *argv;
{
VALUE result = rb_ary_new();
long i;
- if (rb_block_given_p()) {
- char **env;
+ for (i=0; i<argc; i++) {
+ rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
+ }
+ return result;
+}
- if (argc > 0) {
- rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
- }
- env = GET_ENVIRON(environ);
- while (*env) {
- char *s = strchr(*env, '=');
- if (s) {
- VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env),
- rb_tainted_str_new2(s+1));
- if (RTEST(rb_yield(assoc))) {
- rb_ary_push(result, assoc);
- }
- }
- env++;
- }
- FREE_ENVIRON(environ);
+static VALUE
+env_select(argc, argv)
+ int argc;
+ VALUE *argv;
+{
+ VALUE result;
+ long i;
+ char **env;
+
+ if (!rb_block_given_p()) {
+ rb_warn("ENV.select(index..) is deprecated; use ENV.values_at");
+ return env_values_at(argc, argv);
}
- else {
- for (i=0; i<argc; i++) {
- rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
+ }
+ result = rb_ary_new();
+ env = GET_ENVIRON(environ);
+ while (*env) {
+ char *s = strchr(*env, '=');
+ if (s) {
+ VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env),
+ rb_tainted_str_new2(s+1));
+ if (RTEST(rb_yield(assoc))) {
+ rb_ary_push(result, assoc);
+ }
}
+ env++;
}
+ FREE_ENVIRON(environ);
+
return result;
}
@@ -1575,7 +1600,7 @@ env_indexes(argc, argv)
int i;
VALUE indexes = rb_ary_new2(argc);
- rb_warn("ENV.%s is deprecated; use ENV.select",
+ rb_warn("ENV.%s is deprecated; use ENV.values_at",
rb_id2name(rb_frame_last_func()));
for (i=0;i<argc;i++) {
char *v = 0;
@@ -1746,6 +1771,7 @@ Init_Hash()
rb_define_method(rb_cHash,"keys", rb_hash_keys, 0);
rb_define_method(rb_cHash,"values", rb_hash_values, 0);
+ rb_define_method(rb_cHash,"values_at", rb_hash_values_at, -1);
rb_define_method(rb_cHash,"shift", rb_hash_shift, 0);
rb_define_method(rb_cHash,"delete", rb_hash_delete, 1);
@@ -1801,6 +1827,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"empty?", env_empty_p, 0);
rb_define_singleton_method(envtbl,"keys", env_keys, 0);
rb_define_singleton_method(envtbl,"values", env_values, 0);
+ rb_define_singleton_method(envtbl,"values_at", env_values_at, -1);
rb_define_singleton_method(envtbl,"include?", env_has_key, 1);
rb_define_singleton_method(envtbl,"member?", env_has_key, 1);
rb_define_singleton_method(envtbl,"has_key?", env_has_key, 1);
diff --git a/numeric.c b/numeric.c
index 8a76b8f1a1..e0a6011d5b 100644
--- a/numeric.c
+++ b/numeric.c
@@ -912,7 +912,7 @@ num_step(argc, argv, from)
double n = (end - beg)/unit;
long i;
- n = floor(n + n*epsilon) + 1;
+ n = floor(n + n*epsilon + 1);
for (i=0; i<n; i++) {
rb_yield(rb_float_new(i*unit+beg));
}
diff --git a/object.c b/object.c
index c9661a226c..1bbcd5f2ca 100644
--- a/object.c
+++ b/object.c
@@ -899,43 +899,63 @@ rb_mod_const_defined(mod, name)
}
static VALUE
-rb_obj_methods(obj)
+rb_obj_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
VALUE obj;
{
- VALUE argv[1];
+ if (argc == 0) {
+ VALUE args[1];
- argv[0] = Qtrue;
- return rb_class_instance_methods(1, argv, CLASS_OF(obj));
+ args[0] = Qtrue;
+ return rb_class_instance_methods(1, args, CLASS_OF(obj));
+ }
+ return rb_class_instance_methods(argc, argv, CLASS_OF(obj));
}
static VALUE
-rb_obj_protected_methods(obj)
+rb_obj_protected_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
VALUE obj;
{
- VALUE argv[1];
+ if (argc == 0) { /* hack to stop warning */
+ VALUE args[1];
- argv[0] = Qtrue;
- return rb_class_protected_instance_methods(1, argv, CLASS_OF(obj));
+ args[0] = Qtrue;
+ return rb_class_protected_instance_methods(1, args, CLASS_OF(obj));
+ }
+ return rb_class_protected_instance_methods(argc, argv, CLASS_OF(obj));
}
static VALUE
-rb_obj_private_methods(obj)
+rb_obj_private_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
VALUE obj;
{
- VALUE argv[1];
+ if (argc == 0) { /* hack to stop warning */
+ VALUE args[1];
- argv[0] = Qtrue;
- return rb_class_private_instance_methods(1, argv, CLASS_OF(obj));
+ args[0] = Qtrue;
+ return rb_class_private_instance_methods(1, args, CLASS_OF(obj));
+ }
+ return rb_class_private_instance_methods(argc, argv, CLASS_OF(obj));
}
static VALUE
-rb_obj_public_methods(obj)
+rb_obj_public_methods(argc, argv, obj)
+ int argc;
+ VALUE *argv;
VALUE obj;
{
- VALUE argv[1];
+ if (argc == 0) { /* hack to stop warning */
+ VALUE args[1];
- argv[0] = Qtrue;
- return rb_class_public_instance_methods(1, argv, CLASS_OF(obj));
+ args[0] = Qtrue;
+ return rb_class_public_instance_methods(1, args, CLASS_OF(obj));
+ }
+ return rb_class_public_instance_methods(argc, argv, CLASS_OF(obj));
}
static VALUE
@@ -1382,12 +1402,11 @@ Init_Object()
rb_define_method(rb_mKernel, "to_a", rb_any_to_a, 0); /* to be removed */
rb_define_method(rb_mKernel, "to_s", rb_any_to_s, 0);
rb_define_method(rb_mKernel, "inspect", rb_obj_inspect, 0);
- rb_define_method(rb_mKernel, "methods", rb_obj_methods, 0);
- rb_define_method(rb_mKernel, "public_methods", rb_obj_methods, 0);
+ rb_define_method(rb_mKernel, "methods", rb_obj_methods, -1);
rb_define_method(rb_mKernel, "singleton_methods", rb_obj_singleton_methods, -1);
- rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, 0);
- rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, 0);
- rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, 0);
+ rb_define_method(rb_mKernel, "protected_methods", rb_obj_protected_methods, -1);
+ rb_define_method(rb_mKernel, "private_methods", rb_obj_private_methods, -1);
+ rb_define_method(rb_mKernel, "public_methods", rb_obj_public_methods, -1);
rb_define_method(rb_mKernel, "instance_variables", rb_obj_instance_variables, 0);
rb_define_method(rb_mKernel, "instance_variable_get", rb_obj_ivar_get, 1);
rb_define_method(rb_mKernel, "instance_variable_set", rb_obj_ivar_set, 2);
diff --git a/re.c b/re.c
index 9dd9d9bc4d..2bb0411bc0 100644
--- a/re.c
+++ b/re.c
@@ -953,7 +953,7 @@ match_aref(argc, argv, match)
}
static VALUE
-match_select(argc, argv, match)
+match_values_at(argc, argv, match)
int argc;
VALUE *argv;
VALUE match;
@@ -981,6 +981,34 @@ match_select(argc, argv, match)
}
static VALUE
+match_select(argc, argv, match)
+ int argc;
+ VALUE *argv;
+ VALUE match;
+{
+ if (!rb_block_given_p()) {
+ rb_warn("MatchData#select(index..) is deprecated; use MatchData#values_at");
+ return match_values_at(argc, argv, match);
+ }
+ else {
+ struct re_registers *regs = RMATCH(match)->regs;
+ VALUE target = RMATCH(match)->str;
+ VALUE result = rb_ary_new();
+ int i;
+ int taint = OBJ_TAINTED(match);
+
+ for (i=0; i<regs->num_regs; i++) {
+ VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]);
+ if (taint) OBJ_TAINT(str);
+ if (rb_yield(str)) {
+ rb_ary_push(result, str);
+ }
+ }
+ return result;
+ }
+}
+
+static VALUE
match_to_s(match)
VALUE match;
{
@@ -1715,6 +1743,7 @@ Init_Regexp()
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
rb_define_method(rb_cMatch, "[]", match_aref, -1);
rb_define_method(rb_cMatch, "select", match_select, -1);
+ rb_define_method(rb_cMatch, "values_at", match_values_at, -1);
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0);
rb_define_method(rb_cMatch, "to_s", match_to_s, 0);
diff --git a/struct.c b/struct.c
index b1fa31fbd2..d3467bc67b 100644
--- a/struct.c
+++ b/struct.c
@@ -529,6 +529,19 @@ rb_struct_aset(s, idx, val)
return RSTRUCT(s)->ptr[i] = val;
}
+static VALUE
+rb_struct_values_at(argc, argv, s)
+ int argc;
+ VALUE *argv;
+ VALUE s;
+{
+ VALUE result = rb_ary_new();
+ long i;
+
+ for (i=0; i<argc; i++) {
+ rb_ary_push(result, rb_struct_aref(s, argv[i]));
+ }
+}
static VALUE
rb_struct_select(argc, argv, s)
@@ -536,24 +549,23 @@ rb_struct_select(argc, argv, s)
VALUE *argv;
VALUE s;
{
- VALUE result = rb_ary_new();
+ VALUE result;
long i;
- if (rb_block_given_p()) {
- if (argc > 0) {
- rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
- }
- for (i = 0; i < RSTRUCT(s)->len; i++) {
- if (RTEST(rb_yield(RSTRUCT(s)->ptr[i]))) {
- rb_ary_push(result, RSTRUCT(s)->ptr[i]);
- }
- }
+ if (!rb_block_given_p()) {
+ rb_warn("Struct#select(index..) is deprecated; use Struct#values_at");
+ return rb_struct_values_at(argc, argv, s);
}
- else {
- for (i=0; i<argc; i++) {
- rb_ary_push(result, rb_struct_aref(s, argv[i]));
+ if (argc > 0) {
+ rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc);
+ }
+ result = rb_ary_new();
+ for (i = 0; i < RSTRUCT(s)->len; i++) {
+ if (RTEST(rb_yield(RSTRUCT(s)->ptr[i]))) {
+ rb_ary_push(result, RSTRUCT(s)->ptr[i]);
}
}
+
return result;
}
@@ -646,6 +658,7 @@ Init_Struct()
rb_define_method(rb_cStruct, "[]", rb_struct_aref, 1);
rb_define_method(rb_cStruct, "[]=", rb_struct_aset, 2);
rb_define_method(rb_cStruct, "select", rb_struct_select, -1);
+ rb_define_method(rb_cStruct, "values_at", rb_struct_values_at, -1);
rb_define_method(rb_cStruct, "members", rb_struct_members, 0);
}