Module: BigSpoon::ClassMethods

Defined in:
lib/big_spoon.rb

Instance Method Summary collapse

Instance Method Details

#spoon(options = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/big_spoon.rb', line 5

def spoon(options = {}, &block)
  @hooks ||= Hook.for(self)
  @hooks.instance_eval(&block) if block_given?

  unless respond_to?(:_big_spoon_original_method_added)
    class << self
      alias :_big_spoon_original_method_added :method_added
      def _big_spoon_alias_method_added(method_to_hook, *args)
        if @hooks.should_hook?(method_to_hook)
          @hooks.hook! method_to_hook
        end
      end
      alias :method_added :_big_spoon_alias_method_added
    end
  end
  @hooks
end