mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
f001f2f6d5
commit
f595d5b0d2
12 changed files with 243 additions and 100 deletions
29
ChangeLog
29
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.
|
||||
|
|
44
array.c
44
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++) {
|
||||
|
@ -1159,6 +1159,21 @@ rb_ary_collect_bang(ary)
|
|||
return 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;
|
||||
|
@ -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);
|
||||
|
|
29
class.c
29
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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ruby.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------
|
||||
|
|
95
hash.c
95
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else {
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(result, rb_f_getenv(Qnil, argv[i]));
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
|
61
object.c
61
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);
|
||||
|
|
31
re.c
31
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;
|
||||
|
@ -980,6 +980,34 @@ match_select(argc, argv, match)
|
|||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
43
struct.c
43
struct.c
|
@ -529,9 +529,8 @@ rb_struct_aset(s, idx, val)
|
|||
return RSTRUCT(s)->ptr[i] = val;
|
||||
}
|
||||
|
||||
|
||||
static VALUE
|
||||
rb_struct_select(argc, argv, s)
|
||||
rb_struct_values_at(argc, argv, s)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE s;
|
||||
|
@ -539,21 +538,34 @@ rb_struct_select(argc, argv, s)
|
|||
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);
|
||||
}
|
||||
for (i = 0; i < RSTRUCT(s)->len; i++) {
|
||||
if (RTEST(rb_yield(RSTRUCT(s)->ptr[i]))) {
|
||||
rb_ary_push(result, RSTRUCT(s)->ptr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<argc; i++) {
|
||||
rb_ary_push(result, rb_struct_aref(s, argv[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)
|
||||
int argc;
|
||||
VALUE *argv;
|
||||
VALUE s;
|
||||
{
|
||||
VALUE result;
|
||||
long 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue