Class: DiverDown::Trace::RedefineRubyMethods::RubyMethods

Inherits:
Module
  • Object
show all
Defined in:
lib/diver_down/trace/redefine_ruby_methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(class_method_names, instance_method_names) ⇒ RubyMethods

Returns a new instance of RubyMethods.

Parameters:

  • class_method_names (Array<Symbol>)
  • instance_method_names (Array<Symbol>)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/diver_down/trace/redefine_ruby_methods.rb', line 24

def initialize(class_method_names, instance_method_names)
  unless class_method_names.empty?
    def_class_methods = class_method_names.inject(+'') do |buf, method_name|
      buf << <<~METHOD
        def #{method_name}(...)
          super
        end

      METHOD
    end

    mod = Module.new
    mod.module_eval(def_class_methods, __FILE__, __LINE__)
    const_set(:CLASS_METHODS, mod)
  end

  unless instance_method_names.empty?
    instance_method_names.inject(+'') do |_buf, method_name|
      define_method(method_name) do |*_args, **_options|
        super
      end
    end
  end
end

Instance Method Details

#prepend_features(base) ⇒ Object

Parameters:

  • base (Module)


50
51
52
53
# File 'lib/diver_down/trace/redefine_ruby_methods.rb', line 50

def prepend_features(base)
  base.singleton_class.prepend(const_get(:CLASS_METHODS)) if const_defined?(:CLASS_METHODS)
  super
end