From f0f777bc4af05b3d9ef30967e828542ba667d6d6 Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 12 Mar 2012 15:12:07 +0000 Subject: * 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 --- enumerator.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'enumerator.c') 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) -- cgit v1.2.3