From: Johannes Ahl-mann Date: 2005-02-13T10:15:05+09:00 Subject: Re: difficulty with blocks > A shorter version without the generator library would be: > ################################################## > #!/usr/bin/ruby > > def fib > a, b = 1, 1 > loop { > yield a > a, b = b, a + b > } > end > > def fibUpTo n > fib { |val| > break if val > n > yield val > } > end > > a = [] > fibUpTo(20) { |val| a << val } > puts a > ################################################## > thx, this helped a lot. i wasn't aware that one could use "break" inside a block... this looks very readable and natural. Johannes