Created
September 15, 2011 14:23
-
-
Save codenamev/1219363 to your computer and use it in GitHub Desktop.
Reset Constants
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Thanks to Steve Weet's answer on Stack Overflow: | |
# http://stackoverflow.com/questions/3375360/how-to-redefine-a-ruby-constant-without-warning | |
module RemovableConstants | |
def def_if_not_defined(const, value) | |
self.class.const_set(const, value) unless self.class.const_defined?(const) | |
end | |
def redef_without_warning(const, value) | |
self.class.send(:remove_const, const) if self.class.const_defined?(const) | |
self.class.const_set(const, value) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment