class Class

Public Instance Methods

wrap_instance_method(pattern:, &wrapper) click to toggle source
# File lib/method_wrapper.rb, line 9
def wrap_instance_method(pattern:, &wrapper)
  instance_methods.grep(pattern).each do |name|
    method = instance_method(name)
    define_method(name) { |*args, &block| wrapper.call(method.bind(self), *args, &block) }
  end
end
wrap_method(pattern:, &wrapper) click to toggle source
# File lib/method_wrapper.rb, line 2
def wrap_method(pattern:, &wrapper)
  methods.grep(pattern).each do |name|
    method = method(name)
    define_singleton_method(name) { |*args, &block| wrapper.call(method, *args, &block) }
  end
end