class Peeek::Hook::Singleton
Constants
- METHOD_PREFIX
Public Instance Methods
defined?()
click to toggle source
Determine if the method is defined in the object.
@return whether the method is defined in the object
# File lib/peeek/hook/singleton.rb, line 23 def defined? @object.respond_to?(@method_name, true) end
link() { |caller, self, args, block| ... }
click to toggle source
Link the hook to the 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/singleton.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 singleton method. return always “.”
# File lib/peeek/hook/singleton.rb, line 10 def method_prefix METHOD_PREFIX end
target_method()
click to toggle source
@attribute [r] target_method
@return [Method] the method of the object
# File lib/peeek/hook/singleton.rb, line 16 def target_method @object.method(@method_name) end
unlink(original_method)
click to toggle source
Unlink the hook from the method.
@param [Method] original_method original method
# File lib/peeek/hook/singleton.rb, line 42 def unlink(original_method) define_method(&original_method) end
Private Instance Methods
define_method(&block)
click to toggle source
# File lib/peeek/hook/singleton.rb, line 48 def define_method(&block) singleton_class = class << @object; self end singleton_class.__send__(:define_method, @method_name, &block) end