Created
May 19, 2012 00:28
-
-
Save vladiim/2728304 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 Decorator | |
| def initialize(component) | |
| @component = component | |
| end | |
| def method_missing(meth, *args) | |
| if @component.respond_to? meth | |
| @component.send(meth, *args) | |
| else | |
| super | |
| end | |
| end | |
| def respond_to?(meth) | |
| @component.respond_to? meth | |
| end | |
| module Factory | |
| # `decorate` wraps classes in a decorator | |
| def decorate(klass, component) | |
| klass = Object.const_get(klass) | |
| klass_source(klass).call(component) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment