Module: Datadog::MethodWrapping

Includes:
Patcher
Included in:
Shim
Defined in:
lib/ddtrace/augmentation/method_wrapping.rb

Overview

Shorthands for wrapping methods

Instance Method Summary collapse

Methods included from Patcher

included

Methods included from Patcher::CommonMethods

#do_once, #done?, #without_warnings

Instance Method Details

#override_method!(method_name, &block) ⇒ Object

Adds method block directly to the object. Block is evaluated in the context of the object. Faster than #wrap_method!



16
17
18
19
20
21
22
23
24
# File 'lib/ddtrace/augmentation/method_wrapping.rb', line 16

def override_method!(method_name, &block)
  return unless block_given?

  without_warnings do
    define_singleton_method(method_name, &block).tap do
      wrapped_methods.add(method_name)
    end
  end
end

#wrap_method!(original_method, &block) ⇒ Object

Adds method wrapper to the object. Block is evaluated in the original context of the block. Slower than #override_method!



29
30
31
32
33
34
35
36
# File 'lib/ddtrace/augmentation/method_wrapping.rb', line 29

def wrap_method!(original_method, &block)
  return unless block_given?
  original_method = original_method.is_a?(Symbol) ? method(original_method) : original_method

  override_method!(original_method.name) do |*original_args, &original_block|
    block.call(original_method, *original_args, &original_block)
  end
end

#wrapped_methodsObject



9
10
11
# File 'lib/ddtrace/augmentation/method_wrapping.rb', line 9

def wrapped_methods
  @wrapped_methods ||= Set.new
end