Created
November 12, 2012 03:34
-
-
Save infogulch/4057353 to your computer and use it in GitHub Desktop.
Tee class
This file contains 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
cls := new TeeClasses(MyClass, MyOtherClass) | |
inst := new cls() | |
inst.MyMethod("a","b") ; this calls MyMethod from *both* classes | |
class MyClass | |
{ | |
MyMethod(arg1, arg2) | |
{ | |
msgbox % A_ThisFunc " called with: " arg1 ", " arg2 | |
} | |
} | |
class MyOtherClass | |
{ | |
MyMethod(arg1, arg2) | |
{ | |
msgbox % A_ThisFunc " called with: " arg1 ", " arg2 | |
} | |
} | |
class TeeClasses | |
{ | |
__New(classes*) | |
{ | |
obj := {} | |
cls := this.__class "(" | |
for k,c in classes | |
cls .= c.__class "," | |
obj.__class := SubStr(cls, 1, -1) ")" | |
obj.__new := Tee.new | |
obj.__call := Tee.call | |
obj.__bases := classes | |
; return a new, dynamically created class | |
return obj | |
} | |
new(args*) | |
{ | |
Tee.call.(this, "__new", args*) | |
} | |
call(fn, args*) | |
{ | |
for k,v in this.__bases | |
if ObjHasKey(v, fn) | |
v[fn].(this, args*) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment