Created
January 14, 2015 14:54
-
-
Save yitznewton/35061bc05ddcaf159a94 to your computer and use it in GitHub Desktop.
Mixins: good and evil
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
| # evil | |
| module MoarMethods | |
| def foo | |
| end | |
| def bar | |
| end | |
| end | |
| class TooManyMethods | |
| include MoarMethdods | |
| def baz | |
| end | |
| def quux | |
| end | |
| end | |
| # good | |
| module Loggable | |
| def log_method(method_name) | |
| # metaprogramming magic that taps messages to the implementing class and logs stuff | |
| end | |
| end | |
| class Beast | |
| include Loggable | |
| log_method :roar | |
| def roar | |
| output.append('rrr!') | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment