From: david karapetyan Date: 2007-06-04T13:25:50+09:00 Subject: Re: code problems ------=_Part_16756_19185588.1180931151256 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline thanks. i didn't realize i had to provide the block as well when i was creating the closure. i was hoping for a closure that could take a different block every time. i wanted fib to be a function that had access to a and b and every call to fib would require a block. as it is fib has its block fixed at creation time. do you know of a way of doing what i wanted to do originally? On 6/3/07, Nobuyoshi Nakada wrote: > > Hi, > > At Mon, 4 Jun 2007 12:36:50 +0900, > david karapetyan wrote in [ruby-talk:254217]: > > why is the following code not valid > > It is valid. > > > def fibber > > a = 1 > > b = 1 > > lambda do > > yield(a) > > a,b = a+b,a > > end > > end > > irb(main):009:0> fib = fibber{|x|p x} > => # > irb(main):010:0> fib[] > 1 > => [2, 1] > irb(main):011:0> fib[] > 2 > => [3, 2] > irb(main):012:0> fib[] > 3 > => [5, 3] > > -- > Nobu Nakada > > ------=_Part_16756_19185588.1180931151256--