Class: Object

Inherits:
BasicObject
Defined in:
lib/monkey/ext/modexcl/mrimodexcl.rb,
lib/monkey/ext/modexcl/rbxmodexcl.rb

Instance Method Summary collapse

Instance Method Details

#unextend(mod) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/monkey/ext/modexcl/rbxmodexcl.rb', line 4

def unextend(mod)
  raise ArgumentError, "Module is expected" unless mod.is_a?(Module)
  raise ArgumentError, "unextending Kernel is prohibited" if mod == Kernel
  prev = p = metaclass
  while p 
    if (p == mod || (p.respond_to?(:module) && p.module == mod)) 
      prev.set_superclass(p.direct_superclass)
      # remove cache
      self.methods.each do |name|
        name = self.metaclass.send(:normalize_name,name)
        Rubinius::VM.reset_method_cache(name)
      end
      #
      mod.send(:unextended, self) if mod.respond_to?(:unextended)
      return self
    end
    prev = p
    p = p.direct_superclass
  end

end

#uninclude(mod) ⇒ Object

Raises:

  • (ArgumentError)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/monkey/ext/modexcl/rbxmodexcl.rb', line 26

def uninclude(mod)
  raise ArgumentError, "Module is expected" unless mod.is_a?(Module)
  raise ArgumentError, "unincluding Kernel is prohibited" if mod == Kernel
  prev = p = self
  while p 
    if (p == mod || (p.respond_to?(:module) && p.module == mod)) 
      prev.superclass=(p.direct_superclass)
      # remove cache
      self.methods.each do |name|
        name = self.metaclass.send(:normalize_name,name)
        Rubinius::VM.reset_method_cache(name)
      end
      #
      mod.send(:unincluded, self) if mod.respond_to?(:unincluded)
      return self
    end
    prev = p
    p = p.direct_superclass
  end

end