In article <200302090025.11716.transami / transami.net>,
Tom Sawyer  <transami / transami.net> wrote:
>On Saturday 08 February 2003 10:51 pm, Phil Tomson wrote:
>> Is there a way to get a variable in a proc that maintains it's value
>> between different calls of the proc?
>
>a = 1
>p = proc {
>	puts a
>	a+=1
>}
>
[the news server seems to be having trouble, so hofefully this one will 
make it]
I guess I'm looking for a function generator (maybe I'm ready for 
functional programming ;-)

Why can't I do:

#yes there are better ways of achieving the same thing
# it's a contrived example
class MyProcGen
  def initialize(sv=0)
    @start = sv
    @p = proc { puts @start; @start += 1 }
  end
  attr_reader :p
end

mpo = MyProcGen.new
mpo.p.call

?
....it doesn't work, mpo.p is nil (Why?)

Phil