Class: DiverDown::Trace::RedefineRubyMethods::RubyMethods
- Inherits:
-
Module
- Object
- Module
- DiverDown::Trace::RedefineRubyMethods::RubyMethods
- Defined in:
- lib/diver_down/trace/redefine_ruby_methods.rb
Instance Method Summary collapse
-
#initialize(class_method_names, instance_method_names) ⇒ RubyMethods
constructor
A new instance of RubyMethods.
- #prepend_features(base) ⇒ Object
Constructor Details
#initialize(class_method_names, instance_method_names) ⇒ RubyMethods
Returns a new instance of RubyMethods.
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, **| super end end end end |
Instance Method Details
#prepend_features(base) ⇒ Object
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 |