From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-02-09T18:31:39+09:00 Subject: Re: 'static' variables in a proc? In article <200302090025.11716.transami@transami.net>, Tom Sawyer 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