Project

General

Profile

Feature #9602 ยป select-to-accept-args.patch

srawlins (Sam Rawlins), 03/07/2014 04:18 AM

View differences:

enum.c
299 299
}
300 300

  
301 301
static VALUE
302
find_all_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ary))
302
find_all_iter_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, ary))
303 303
{
304 304
    ENUM_WANT_SVALUE();
305 305

  
......
310 310
}
311 311

  
312 312
static VALUE
313
find_all_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args))
314
{
315
    NODE *memo = RNODE(args);
316
    VALUE ary = memo->u1.value;
317
    long j;
318
    ENUM_WANT_SVALUE();
319

  
320
    for (j=0; j<RARRAY_LEN(ary); j++) {
321
	if (RTEST(rb_funcall(RARRAY_AREF(ary, j), id_eqq, 1, i))) {
322
	    rb_ary_push(memo->u2.value, i);
323
	}
324
    }
325
    return Qnil;
326
}
327

  
328
static VALUE
313 329
enum_size(VALUE self, VALUE args, VALUE eobj)
314 330
{
315 331
    VALUE r;
......
338 354
 */
339 355

  
340 356
static VALUE
341
enum_find_all(VALUE obj)
357
enum_find_all(int argc, VALUE *argv, VALUE obj)
342 358
{
343 359
    VALUE ary;
360
    NODE *memo;
361
    VALUE items = Qnil;
344 362

  
345
    RETURN_SIZED_ENUMERATOR(obj, 0, 0, enum_size);
363
    if (argc == 0) {
364
	RETURN_SIZED_ENUMERATOR(obj, argc, argv, enum_size);
346 365

  
347
    ary = rb_ary_new();
348
    rb_block_call(obj, id_each, 0, 0, find_all_i, ary);
366
	ary = rb_ary_new();
367
	rb_block_call(obj, id_each, 0, 0, find_all_iter_i, ary);
368
    } else {
369
	rb_scan_args(argc, argv, "*", &items);
370

  
371
	if (rb_block_given_p())
372
	    rb_warn("given block not used");
373

  
374
	ary = rb_ary_new();
375
	memo = NEW_MEMO(items, ary, 0);
376
	rb_block_call(obj, id_each, 0, 0, find_all_i, (VALUE)memo);
377
    }
349 378

  
350 379
    return ary;
351 380
}
......
3052 3081
    rb_define_method(rb_mEnumerable, "find", enum_find, -1);
3053 3082
    rb_define_method(rb_mEnumerable, "detect", enum_find, -1);
3054 3083
    rb_define_method(rb_mEnumerable, "find_index", enum_find_index, -1);
3055
    rb_define_method(rb_mEnumerable, "find_all", enum_find_all, 0);
3056
    rb_define_method(rb_mEnumerable, "select", enum_find_all, 0);
3084
    rb_define_method(rb_mEnumerable, "find_all", enum_find_all, -1);
3085
    rb_define_method(rb_mEnumerable, "select", enum_find_all, -1);
3057 3086
    rb_define_method(rb_mEnumerable, "reject", enum_reject, 0);
3058 3087
    rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
3059 3088
    rb_define_method(rb_mEnumerable, "map", enum_collect, 0);