Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added actsAs combinator #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

added actsAs combinator #15

wants to merge 1 commit into from

Conversation

ludicast
Copy link
Contributor

Okay, this was a fun xmas one while my toddler is napping.

I used your around combinator to build an actsAs combinator. This assigns roles a la DCI.

So the equivalent of this ruby DCI example:

def initialize source_account, destination_account
    @source_account = source_account.extend SourceAccount
    @destination_account = destination_account.extend DestinationAccount
    doStuff...
end

is the hotter

initialize: actsAs(SourceAccount, DestinationAccount) (@sourceAccount, @destinationaccount)->
  doStuff...

This has the big benefit of removing the role after the method invocation (whereas in the ruby example the modules crash the inheritance party). I named it actAs as an obvious "shout out".

Also, actsAs takes objects as input and steals their methods for the target objects. If the parameters to actsAs are instead classes, then it steals their class methods, not instance methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant