Class: Peeek::Hook::Singleton
- Defined in:
- lib/peeek/hook/singleton.rb
Constant Summary collapse
- METHOD_PREFIX =
'.'.freeze
Instance Attribute Summary collapse
-
#method_prefix ⇒ String
readonly
Method prefix for singleton method.
-
#target_method ⇒ Method
readonly
The method of the object.
Instance Method Summary collapse
-
#defined? ⇒ Boolean
Determine if the method is defined in the object.
-
#link {|backtrace, receiver, args| ... } ⇒ Object
Link the hook to the method.
-
#unlink(original_method) ⇒ Object
Unlink the hook from the 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 singleton method. return always “.”.
10 11 12 |
# File 'lib/peeek/hook/singleton.rb', line 10 def method_prefix METHOD_PREFIX end |
#target_method ⇒ Method (readonly)
Returns the method of the object.
16 17 18 |
# File 'lib/peeek/hook/singleton.rb', line 16 def target_method @object.method(@method_name) end |
Instance Method Details
#defined? ⇒ Boolean
Determine if the method is defined in the object.
23 24 25 |
# File 'lib/peeek/hook/singleton.rb', line 23 def defined? @object.respond_to?(@method_name, true) end |
#link {|backtrace, receiver, args| ... } ⇒ Object
Link the hook to the method.
34 35 36 37 |
# File 'lib/peeek/hook/singleton.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 method.
42 43 44 |
# File 'lib/peeek/hook/singleton.rb', line 42 def unlink(original_method) define_method(&original_method) end |