class Peeek::Hook::Instance
Constants
- METHOD_PREFIX
Public Instance Methods
defined?()
click to toggle source
Determine if the instance method is defined in the object.
@return whether the instance method is defined in the object
# File lib/peeek/hook/instance.rb, line 23 def defined? @object.method_defined?(@method_name) or @object.private_method_defined?(@method_name) end
link() { |caller, self, args, block| ... }
click to toggle source
Link the hook to the instance method.
@yield [backtrace, receiver, args] callback for hook @yieldparam [Array<String>] backtrace backtrace the call occurred @yieldparam [Object] receiver object that received the call @yieldparam [Array] args arguments at the call @yieldreturn [Object] return value of the original method
# File lib/peeek/hook/instance.rb, line 34 def link raise ArgumentError, 'block not supplied' unless block_given? define_method { |*args, &block| yield caller, self, args, block } end
method_prefix()
click to toggle source
@attribute [r] method_prefix
@return [String] method prefix for instance method. return always “#”
# File lib/peeek/hook/instance.rb, line 10 def method_prefix METHOD_PREFIX end
target_method()
click to toggle source
@attribute [r] target_method
@return [UnboundMethod] the instance method of the object
# File lib/peeek/hook/instance.rb, line 16 def target_method @object.instance_method(@method_name) end
unlink(original_method)
click to toggle source
Unlink the hook from the instance method.
@param [UnboundMethod] original_method original method
# File lib/peeek/hook/instance.rb, line 42 def unlink(original_method) define_method(original_method) end
Private Instance Methods
define_method(*args, &block)
click to toggle source
# File lib/peeek/hook/instance.rb, line 48 def define_method(*args, &block) @object.__send__(:define_method, @method_name, *args, &block) end