Skip to content

Instantly share code, notes, and snippets.

@infogulch
Created November 12, 2012 03:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infogulch/4057353 to your computer and use it in GitHub Desktop.
Save infogulch/4057353 to your computer and use it in GitHub Desktop.
Tee class
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