Skip to content

Commit

Permalink
* enum.c (enum_find): mention about ifnone argument. [ruby-talk:90003]
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Jan 16, 2004
1 parent 2cb9e7a commit 8e8c7f0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>enum</i> to <em>block</em>. Returns the
* first for which <em>block</em> is not <code>false</code>. Returns
* <code>nil</code> if no object matches.
* first for which <em>block</em> is not <code>false</code>. If no
* object matches, calls <i>ifnone</i> and returns its result when it
* is specified, or returns <code>nil</code>
*
* (1..10).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> nil
* (1..100).detect {|i| i % 5 == 0 and i % 7 == 0 } #=> 35
Expand Down Expand Up @@ -198,7 +199,7 @@ collect_i(i, ary)
VALUE i, ary;
{
rb_ary_push(ary, rb_yield(i));

return Qnil;
}

Expand All @@ -207,7 +208,7 @@ collect_all(i, ary)
VALUE i, ary;
{
rb_ary_push(ary, i);

return Qnil;
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8e8c7f0

Please sign in to comment.