Module: Peekaboo::SingletonMethods

Defined in:
lib/peekaboo.rb

Overview

Contains methods added to every class that includes the Peekaboo module, either through direct or auto inclusion.

Instance Method Summary collapse

Instance Method Details

#enable_tracing_on(*method_names) ⇒ Object

Enables instance method tracing on calling class.

Examples:

Trace a couple of methods

class SomeClass
  include Peekaboo

  def method1; end
  def method2; end
  def method3; end
end

# Tracing will be performed on method1(), method2(), but NOT method3()
SomeClass.enable_tracing_on :method1, :method2

Parameters:

  • method_names (*Symbol)

    the list of methods that you want to trace

Raises:

  • (RuntimeError)

    when attempting to add a method that is already being traced



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/peekaboo.rb', line 112

def enable_tracing_on *method_names
  include Peekaboo unless @_hooked_by_peekaboo
  
  method_names.each do |method_name|
    unless peek_list.include? method_name
      peek_list << method_name
      Peekaboo.wrap_method self, method_name if self.instance_methods(false).include? method_name.to_s
    else
      raise "Already tracing `#{method_name}'"
    end
  end
end

#peek_listArray<Symbol>

Returns a list of instance methods that are being traced inside calling class.

Returns:

  • (Array<Symbol>)

    a list of instance methods that are being traced inside calling class



90
91
92
# File 'lib/peekaboo.rb', line 90

def peek_list
  self::PEEKABOO_METHOD_LIST
end