Created
May 3, 2016 00:38
-
-
Save richo/2efaeca3f61fceaeff2c62b53d493226 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
| def override_class_method(klass, meth) | |
| # FIXME: This is somehow ugly. We should reduce the amount of | |
| # `evaled` code. | |
| str = " class << #{klass} | |
| original = '#{meth}'.to_sym | |
| saved_meth_name = '#{get_saved_method_name(meth)}'.to_sym | |
| new_method = '#{meth}_modified'.to_sym | |
| alias_method saved_meth_name, original | |
| p = Instrumentation.define_callback_method(original, saved_meth_name, | |
| #{klass}) | |
| define_method(new_method, p) | |
| private new_method | |
| method_kind = nil | |
| case | |
| when public_method_defined?(original) | |
| method_kind = :public | |
| when protected_method_defined?(original) | |
| method_kind = :protected | |
| when private_method_defined?(original) | |
| method_kind = :private | |
| end | |
| alias_method original, new_method | |
| send(method_kind, original) | |
| private saved_meth_name | |
| end " | |
| eval str | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment