method-combinators icon indicating copy to clipboard operation
method-combinators copied to clipboard

added actsAs combinator

Open ludicast opened this issue 12 years ago • 0 comments

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.

ludicast avatar Dec 25 '12 18:12 ludicast