How do I temporarily monkey with a global module constant?
Posted
by Daniel
on Stack Overflow
See other posts from Stack Overflow
or by Daniel
Published on 2010-05-27T19:23:31Z
Indexed on
2010/05/27
20:01 UTC
Read the original article
Hit count: 278
Greetings,
I want to tinker with the global memcache object, and I found the following problems.
- Cache is a constant
- Cache is a module
I only want to modify the behavior of Cache globally for a small section of code for a possible major performance gain.
Since Cache is a module, I can't re-assign it, or encapsulate it.
I Would Like To Do This:
Deep in a controller method...
code code code...
old_cache = Cache
Cache = MyCache.new
code code code...
Cache = old_cache
code code code...
However, since Cache is a constant I'm forbidden to change it. Threading is not an issue at the moment. :)
Would it be "good manners" for me to just alias_method the special code I need just for a small section of code and then later unalias it again? That doesn't pass the smell test IMHO.
Does anyone have any ideas?
TIA,
-daniel
© Stack Overflow or respective owner