Closed prateeksen closed 1 year ago
We offer fidelity here, a problem is that there is no easy win here.
Some fights can be won with prepend, other fights with alias method. It depends on how nicely the ecosystem plays.
As of my knowledge, Prepend can be used in place of both hooks, class_eval & instance_eval. I don't understand the point you made about " Some fights can be won with prepend, other fights with alias method "
I would like to provide both samples here: class_eval Example
module MyMysql2Client
Mysql2::Client.class_eval do
prepend MyMysql2Client
end
def query(sql, options = {})
// Do whatever you want to do
return super
end
end
instance_eval example
module MyKlass
Klass.singleton_class.prepend(MyKlass)
def my_method(*var)
// Do whatever you want to do
return super
end
end
Can you provide more detail if you have any other concern.
see:
https://github.com/MiniProfiler/rack-mini-profiler/issues/437
PR totally welcome for something like: https://github.com/MiniProfiler/rack-mini-profiler/commit/d7e30177859a43fd0fba0cc54ad04bb4fe37e6a4
If we move to prepend we may break some people who patch not using prepend.
Reason: rack-mini-profiler uses alias for monkey patching As it is already recommend to use Module#prepend instead of alias method chain to overcome the above exception. A very good explanation is present here: https://stackoverflow.com/a/4471202/7948740