diff --git a/enum.c b/enum.c index ef7fe951c3..0b88176fb6 100644 --- a/enum.c +++ b/enum.c @@ -92,12 +92,13 @@ find_i(i, memo) /* * call-seq: - * enum.detect {| obj | block } => obj or nil - * enum.find {| obj | block } => obj or nil + * enum.detect(ifnone = nil) {| obj | block } => obj or nil + * enum.find(ifnone = nil) {| obj | block } => obj or nil * * Passes each entry in enum to block. Returns the - * first for which block is not false. Returns - * nil if no object matches. + * first for which block is not false. If no + * object matches, calls ifnone and returns its result when it + * is specified, or returns nil * * (1..10).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil * (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35 @@ -198,7 +199,7 @@ collect_i(i, ary) VALUE i, ary; { rb_ary_push(ary, rb_yield(i)); - + return Qnil; } @@ -207,7 +208,7 @@ collect_all(i, ary) VALUE i, ary; { rb_ary_push(ary, i); - + return Qnil; } @@ -229,7 +230,7 @@ enum_collect(obj) VALUE obj; { VALUE ary = rb_ary_new(); - + rb_iterate(rb_each, obj, rb_block_given_p() ? collect_i : collect_all, ary); return ary; @@ -250,7 +251,7 @@ enum_to_a(obj) VALUE obj; { VALUE ary = rb_ary_new(); - + rb_iterate(rb_each, obj, collect_all, ary); return ary;