module Datadog::MethodWrapping

Shorthands for wrapping methods

Public Instance Methods

override_method!(method_name, &block) click to toggle source

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

# 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) click to toggle source

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

# 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_methods() click to toggle source
# File lib/ddtrace/augmentation/method_wrapping.rb, line 9
def wrapped_methods
  @wrapped_methods ||= Set.new
end