LAMBEAU Bernard
4/8/2009 2:41:00 PM
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
<James.French@naturalmotion.com> wrote:
> Hi,
>
> Could anyone suggest an elegant way of doing something like:
>
> $directXSDKBootstrapped =3D false
>
> def bootstrapDirectXSDK
> =A0if !$directXSDKBootstrapped
> =A0 =A0bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
> =A0 =A0$directXSDKBootstrapped =3D true
> =A0 =A0$directXSDKBootstrapped.freeze
> =A0end
> end
>
> Obviously the intention is to only do something the first time it is call=
ed. Maybe some little reusable util? I have a number of different bootstrap=
functions I want to apply this to.
>
> Cheers,
> James
>
>