From: Phlip Date: 2009-04-08T23:40:13+09:00 Subject: Re: performing an action only the first time a function called Don't think of them as "functions". Think of them as "methods", and always put them inside classes. James French wrote: > Hi, > > Could anyone suggest an elegant way of doing something like: > > $directXSDKBootstrapped = false > > def bootstrapDirectXSDK > if !$directXSDKBootstrapped > bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}") > $directXSDKBootstrapped = true > $directXSDKBootstrapped.freeze > end > end class Whatever def bootstrapDirectXSDK @@directXSDKBootstrapped ||= bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}") end end That's teh "proxy pattern" in Ruby...