Class: Bogus::OverwritesClasses

Inherits:
Object
  • Object
show all
Defined in:
lib/bogus/fakes/overwrites_classes.rb

Instance Method Summary collapse

Instance Method Details

#overwrite(full_name, new_klass) ⇒ Object



2
3
4
5
6
7
8
# File 'lib/bogus/fakes/overwrites_classes.rb', line 2

def overwrite(full_name, new_klass)
  modules = full_name.split('::')
  klass_name = modules.pop
  parent_module = modules.reduce(Object) { |mod, name| mod.const_get(name) }
  parent_module.send(:remove_const, klass_name)
  parent_module.const_set(klass_name, new_klass)
end