Created
March 21, 2013 18:31
-
-
Save jferris/5215457 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
| class InspectorGadget < BasicObject | |
| def initialize(target, notifier) | |
| @target = target | |
| @notifier = notifier | |
| end | |
| def method_missing(name, *args, &block) | |
| result = @target.public_send(name, *args, &block) | |
| @notifier.invocation(name, args, block, result) | |
| result | |
| rescue ::Exception => exception | |
| @notifier.invocation(name, args, block, exception) | |
| Kernel.raise | |
| end | |
| def respond_to_missing?(method_name, include_private = false) | |
| @target.respond_to_missing?(method_name, include_private) || super | |
| end | |
| end |
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
| class PrintNotifier | |
| def initialize(output) | |
| @output = output | |
| end | |
| def invocation(name, args, block, result) | |
| inspected_args = args.map(&:inspect).join(', ') | |
| if block | |
| inspected_args << "&#{block.inspect}" | |
| end | |
| @output.puts "#{name}(#{inspected_args})" | |
| @output.puts "=> #{result.inspect}" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment