Created
October 16, 2018 07:26
-
-
Save eliav-lavi/46bec8081cb979b7e63e19b96f992728 to your computer and use it in GitHub Desktop.
Wrapping methods with prepend
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 FooWrapper | |
| def bar | |
| puts "this will happen before the real bar!" | |
| super | |
| end | |
| end | |
| class Foo | |
| prepend FooWrapper | |
| def bar | |
| :bar_return_value | |
| end | |
| end | |
| # Foo.new.bar | |
| # this will happen before the real bar! | |
| # => :bar_return_value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment