summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-16 14:07:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-16 14:07:06 +0000
commitdb68e1714eb75424fd79feccc6f0ef63898321f5 (patch)
treec09ea763844509c968d8602b1a660694242eaa4c /enum.c
parente87765d43eb66c1d6bfc94b65a71336afd019626 (diff)
* enum.c (enum_find): mention about ifnone argument. [ruby-talk:90003]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@5474 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/enum.c b/enum.c
index ef7fe95..0b88176 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 <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
@@ -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;