mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
added list of subclasses per class
This commit is contained in:
parent
252b63f8f6
commit
1df9ccf178
@ -31,6 +31,7 @@ end
|
||||
|
||||
local function _createClass(name, super)
|
||||
local klass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict={} }
|
||||
klass.subclasses = setmetatable({}, {__mode = "k"})
|
||||
|
||||
_setClassDictionariesMetatables(klass)
|
||||
_setClassMetatable(klass)
|
||||
@ -91,6 +92,7 @@ function Object.static:subclass(name)
|
||||
local subclass = _createClass(name, self)
|
||||
_setClassMetamethods(subclass)
|
||||
_setDefaultInitializeMethod(subclass, self)
|
||||
self.subclasses[subclass] = true
|
||||
self:subclassed(subclass)
|
||||
|
||||
return subclass
|
||||
|
@ -48,6 +48,10 @@ context('Object', function()
|
||||
assert_equal(SubClass.super, Object)
|
||||
end)
|
||||
|
||||
test('it includes the subclass in the list of subclasses', function()
|
||||
assert_true(Object.subclasses[SubClass])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
@ -69,6 +69,10 @@ context('A Class', function()
|
||||
assert_equal(SubClass, AClass.child)
|
||||
end)
|
||||
|
||||
test('it includes the subclass in the list of subclasses', function()
|
||||
assert_true(AClass.subclasses[SubClass])
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user