From: "David A. Black" Date: 2004-10-30T19:22:50+09:00 Subject: Re: reuse passed proc later? On Sat, 30 Oct 2004, David Gurba wrote: > Hello Everyone, > > I'm new to Ruby and some of its features... > > I want to do the following (with as little modfication as necessary): > > call a passed block to a function at some later time... Eg. > > class A > > def foo(&block) > @func = block > end > end > > a = A.new > num = a.func.call { print "12" } > > ...but func is an unknown method, and attr_accessor :func doesn't help either.... > > any nice solution? In your example you never call foo, so @func never gets assigned to. Is this something like what you want to do? class A def func(&block) @func ||= block end end a = A.new a.func { 12 } num = a.func.call puts num # 12 David -- David A. Black dblack@wobblini.net