Module: Konstructor::KonstructorMethodHook
- Defined in:
- lib/konstructor/konstructor_method_hook.rb
Overview
:nodoc:
Class Method Summary collapse
-
.setup(base) ⇒ Object
Experimental and currently not used
method_addedhook approach protecting against method_added overrides that are not calling super (hopefully, there is no such code in the wild).
Class Method Details
.setup(base) ⇒ Object
Experimental and currently not used method_added hook approach protecting against method_added overrides that are not calling super (hopefully, there is no such code in the wild).
Since method_added hook is idempotent, there would be no harm done even if overridding method_added actually had super call and Konstructor’s hook would be called twice as a result of this.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/konstructor/konstructor_method_hook.rb', line 11 def self.setup(base) method_added_method = base.method(:method_added) if method_added_method.source_location method_added_file_path = method_added_method.source_location.first return if method_added_file_path.include?('konstructor_method_hook') end base.instance_exec do private alias konstructor_super_method_added method_added def method_added(name) @konstructor ||= Konstructor.new(self) @konstructor.method_added_to_klass(name) konstructor_super_method_added(name) end end end |