Created
May 19, 2012 00:28
-
-
Save vladiim/2728302 to your computer and use it in GitHub Desktop.
# `factorize` allows Classes to create new class methods it does this by # calling public_method(:new) on the class rather than directly calling new # therebye ensuring single responsibility is followed
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 Factorizer | |
| # `factorize` allows Classes to create new class methods it does this by | |
| # calling public_method(:new) on the class rather than directly calling new | |
| # therebye ensuring single responsibility is followed | |
| def factorize(klass, *attrs) | |
| klass = Object.const_get(klass) | |
| klass_source(klass).call(*attrs) | |
| end | |
| private | |
| def klass_source(klass) | |
| klass.public_method(:new) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment