codenamev
9/15/2011 - 2:23 PM

Reset Constants

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