Advertisement
LeonMMS

Untitled

Mar 31st, 2019
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.37 KB | None | 0 0
  1. class Object
  2.   def def_if_not_defined(const, value)
  3.     mod = self.is_a?(Module) ? self : self.class
  4.     mod.const_set(const, value) unless mod.const_defined?(const)
  5.   end
  6.  
  7.   def redef_without_warning(const, value)
  8.     mod = self.is_a?(Module) ? self : self.class
  9.     mod.send(:remove_const, const) if mod.const_defined?(const)
  10.     mod.const_set(const, value)
  11.   end
  12. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement