From: Chris Carter Date: 2007-08-17T05:20:52+09:00 Subject: Re: Lazy function definition pattern in Ruby? On 8/16/07, dblack@rubypal.com wrote: > You could do this (and I think it's similar to the "once" technique > [pattern?] that's used in the Date library and talked about in the > Pickaxe): > > def my_time > t = Time.now > (class << self; self; end).class_eval do > define_method(:my_time) { t } > end > t > end Why not just use a closure, and do it the way you would in JS? foo = proc { x=Time.now; foo = proc { x } }; foo.call Then you just access it with foo[]/foo.call -- Chris Carter concentrationstudios.com brynmawrcs.com