1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@1905 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2001-12-11 03:48:08 +00:00
parent 8a91c99905
commit a59c599209
10 changed files with 203 additions and 6 deletions

View file

@ -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<argc; i++) {
rb_ary_push(result, rb_struct_aref(s, argv[i]));
}
}
return result;
}
static VALUE
rb_struct_equal(s, s2)
VALUE s, s2;
@ -556,6 +584,7 @@ Init_Struct()
rb_define_method(rb_cStruct, "each", rb_struct_each, 0);
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, "members", rb_struct_members, 0);
}