Class: Peeek::Hook::Instance
- Defined in:
- lib/peeek/hook/instance.rb
Constant Summary collapse
- METHOD_PREFIX =
'#'.freeze
Instance Attribute Summary collapse
-
#method_prefix ⇒ String
readonly
Method prefix for instance method.
-
#target_method ⇒ UnboundMethod
readonly
The instance method of the object.
Instance Method Summary collapse
-
#defined? ⇒ Boolean
Determine if the instance method is defined in the object.
-
#link {|backtrace, receiver, args| ... } ⇒ Object
Link the hook to the instance method.
-
#unlink(original_method) ⇒ Object
Unlink the hook from the instance method.
Methods inherited from Linker
Constructor Details
This class inherits a constructor from Peeek::Hook::Linker
Instance Attribute Details
#method_prefix ⇒ String (readonly)
Returns method prefix for instance method. return always “#”.
10 11 12 |
# File 'lib/peeek/hook/instance.rb', line 10 def method_prefix METHOD_PREFIX end |
#target_method ⇒ UnboundMethod (readonly)
Returns the instance method of the object.
16 17 18 |
# File 'lib/peeek/hook/instance.rb', line 16 def target_method @object.instance_method(@method_name) end |
Instance Method Details
#defined? ⇒ Boolean
Determine if the instance method is defined in the object.
23 24 25 |
# File 'lib/peeek/hook/instance.rb', line 23 def defined? @object.method_defined?(@method_name) or @object.private_method_defined?(@method_name) end |
#link {|backtrace, receiver, args| ... } ⇒ Object
Link the hook to the instance method.
34 35 36 37 |
# File 'lib/peeek/hook/instance.rb', line 34 def link raise ArgumentError, 'block not supplied' unless block_given? define_method { |*args| yield caller, self, args } end |
#unlink(original_method) ⇒ Object
Unlink the hook from the instance method.
42 43 44 |
# File 'lib/peeek/hook/instance.rb', line 42 def unlink(original_method) define_method(original_method) end |