From: LAMBEAU Bernard Date: 2009-04-08T23:40:43+09:00 Subject: Re: performing an action only the first time a function called One way to do it, which requires a good understanding of metaprogramming, could be as follows: class Class # Replaces the method whose name is provided by a # method that calls the original one the first time it is called # and by a noop method for subsequent calls. def one_call_only(method_name) # implement me end end class MyClass def bootstrapDirectXSDK bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}") end one_call_only :bootstrapDirectXSDK end I'm not sure it's the simplest way to do it. I can sketch the actual code of one_call_only if it helps. blambeau On Wed, Apr 8, 2009 at 4:29 PM, 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 > > Obviously the intention is to only do something the first time it is called. Maybe some little reusable util? I have a number of different bootstrap functions I want to apply this to. > > Cheers, > James > >