Module: Fiveruns::Tuneup::Superlative

Defined in:
lib/fiveruns/tuneup/superlative.rb

Class Method Summary collapse

Class Method Details

.on(target, level = :singleton, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fiveruns/tuneup/superlative.rb', line 10

def self.on(target, level = :singleton, &block)
  wedge = Module.new(&block)
  case level
  when :singleton
    save = Module.new
    wedge.instance_methods.each do |meth|
      save.send(:define_method, meth, target.method(meth))
      if target.metaclass.instance_methods.include?(meth.to_s)
        target.metaclass.send(:remove_method, meth)
      end
    end
    target.extend save
    target.extend wedge
  when :instances # Instance
    wedges << wedge
    offset = wedges.size - 1
    hook = Module.new
    hook.module_eval %{
      def new(*args, &block)
        super.extend(Fiveruns::Tuneup::Superlative.wedges[#{offset}])
      end
    }
    target.extend hook
  end
end

.wedgesObject



6
7
8
# File 'lib/fiveruns/tuneup/superlative.rb', line 6

def self.wedges
  @wedges ||= []
end