Created
November 25, 2012 19:18
-
-
Save aaronjensen/4144850 to your computer and use it in GitHub Desktop.
DCI dynamic super class
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
| # Define a new role "super class" | |
| Applicant = Role.new do | |
| def apply | |
| # ... | |
| end | |
| end | |
| # Applicant[User] returns a cacheable class that inherits from User but | |
| # has the behavior of the Applicant role as well | |
| # i.e. calling Applicant[User] is equivalent to writing this: | |
| # class ApplicantOfUser < User | |
| # def apply | |
| # # ... | |
| # end | |
| # end | |
| applicant = Applicant[User].find_by_email 'my@email.com' | |
| applicant.apply |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment