Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created November 25, 2012 19:18
Show Gist options
  • Select an option

  • Save aaronjensen/4144850 to your computer and use it in GitHub Desktop.

Select an option

Save aaronjensen/4144850 to your computer and use it in GitHub Desktop.
DCI dynamic super class
# 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