From 2cfcc42a17d7de808fad5468cf93e1a79b839ab0 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 11 Dec 2001 03:48:08 +0000 Subject: * string.c (rb_str_match_m): should convert an argument into regexp if it's a string. * array.c (rb_ary_select): Array#select(n,m,...) now works like Array#indexes(n,m,..). [new, experimental] * hash.c (rb_hash_select): ditto. * hash.c (env_select): ditto. * re.c (match_select): ditto. * struct.c (rb_struct_select): ditto. * gc.c (STR_ASSOC): use FL_USER3 instead of FL_USER2. * parse.y (str_extend): make up pushback call. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@1905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- struct.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'struct.c') diff --git a/struct.c b/struct.c index cfc144757..21043cba9 100644 --- a/struct.c +++ b/struct.c @@ -507,6 +507,34 @@ rb_struct_aset(s, idx, val) return RSTRUCT(s)->ptr[i] = val; } + +static VALUE +rb_struct_select(argc, argv, s) + int argc; + VALUE *argv; + VALUE 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(RARRAY(s)->ptr[i]))) { + rb_ary_push(result, RSTRUCT(s)->ptr[i]); + } + } + } + else { + for (i=0; i