Nobuyoshi Nakada
6/4/2007 4:06:00 AM
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}
=> #<Proc:0xb7c63a74@(irb):4>
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