Skip to content

Instantly share code, notes, and snippets.

@codenamev
Created September 15, 2011 14:23
Show Gist options
  • Save codenamev/1219363 to your computer and use it in GitHub Desktop.
Save codenamev/1219363 to your computer and use it in GitHub Desktop.
Reset Constants
# 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