Last active
May 29, 2019 03:45
-
-
Save hanachin/fd6d42c431fd1b700bd49863a9773fe3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Hi | |
instance_methods_snapshot = [] | |
TracePoint.trace(:class) do |tp| | |
next unless tp.self == self | |
# Hi.singleton_class.prepend Module.new { define_method(:method_added) { "ここで最小限のスナップショットを取ることも可能" } } | |
instance_methods_snapshot = instance_methods.map(&method(:instance_method)) | |
end | |
TracePoint.trace(:end) do |tp| | |
next unless tp.self == self | |
instance_methods_snapshot.each do |instance_method_snapshot| | |
method_name = instance_method_snapshot.name | |
current_instance_method = instance_method(method_name) | |
next if instance_method_snapshot == current_instance_method | |
module_eval do | |
define_method(method_name) do | |
instance_method_snapshot.bind(self).call | |
current_instance_method.bind(self).call | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ツイート可能