summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-12 15:12:07 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-12 15:12:07 +0000
commitf0f777bc4af05b3d9ef30967e828542ba667d6d6 (patch)
treea87b7ebbf8145b95ba80e3422d36882e18fa7b50 /enumerator.c
parentb681457f018c9d8ef2233a2f97ab998d629182c9 (diff)
* enumerator.c (enumerable_lazy): added the documenation of Enumerable#lazy.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/enumerator.c b/enumerator.c
index 8e02021386..5e91673899 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -1247,6 +1247,27 @@ lazy_initialize(VALUE self, VALUE obj)
/*
* call-seq:
* e.lazy -> lazy_enumerator
+ *
+ * Returns a lazy enumerator, whose methods map/collect,
+ * flat_map/collect_concat, select/find_all, reject, and grep call blocks
+ * only on an as-needed basis.
+ *
+ * === Example
+ *
+ * The following program shows all pythagorean triples less than 100:
+ *
+ * def pythagorean_triples
+ * (1..Float::INFINITY).lazy.flat_map {|z|
+ * (1..z).flat_map {|x|
+ * (x..z).select {|y|
+ * x**2 + y**2 == z**2
+ * }.map {|y|
+ * [x, y, z]
+ * }
+ * }
+ * }
+ * end
+ * p pythagorean_triples.take_while { |x, y, z| z < 100 }
*/
static VALUE
enumerable_lazy(VALUE obj)