Class: Module

Inherits:
Object
  • Object
show all
Defined in:
lib/reincarnation.rb

Instance Method Summary collapse

Instance Method Details

#basesObject



8
9
10
# File 'lib/reincarnation.rb', line 8

def bases
  @bases ||= []
end

#buryObject



25
26
27
# File 'lib/reincarnation.rb', line 25

def bury
  parent.__send__(:remove_const, name_without_namespace)
end

#included(base) ⇒ Object



4
5
6
# File 'lib/reincarnation.rb', line 4

def included(base)
  bases << base
end

#name_without_namespaceObject



21
22
23
# File 'lib/reincarnation.rb', line 21

def name_without_namespace
  name.gsub(/.*::/, '')
end

#poke_bases(m) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/reincarnation.rb', line 12

def poke_bases(m)
  bases.each do |b|
    b.module_eval do
      include(m)
      poke_bases(m)
    end
  end
end

#reincarnateObject



29
30
31
32
33
34
# File 'lib/reincarnation.rb', line 29

def reincarnate
  buried = bury
  reborn = parent.const_set(name_without_namespace, Module.new)
  poke_bases(reborn)
  reborn.module_eval { include buried }
end