From 0f20fc42884113f5478da0d7d7a9975283a7ced5 Mon Sep 17 00:00:00 2001 From: kikito Date: Sun, 13 Dec 2015 01:13:49 +0100 Subject: [PATCH] removes default includes(mixin) method and __mixins attribute --- middleclass.lua | 14 +------- spec/default_methods_spec.lua | 67 ----------------------------------- 2 files changed, 1 insertion(+), 80 deletions(-) diff --git a/middleclass.lua b/middleclass.lua index 88634c2..d9c37e2 100644 --- a/middleclass.lua +++ b/middleclass.lua @@ -109,7 +109,7 @@ local function _setClassMetatable(aClass) end local function _createClass(name, super) - local aClass = { name = name, super = super, static = {}, __mixins = {}, __instanceDict = {}, __instanceMeta = {} } + local aClass = { name = name, super = super, static = {}, __instanceDict = {}, __instanceMeta = {} } aClass.subclasses = setmetatable({}, {__mode = "k"}) _setClassDictionariesMetatables(aClass) @@ -141,7 +141,6 @@ local function _includeMixin(aClass, mixin) end end if type(mixin.included)=="function" then mixin:included(aClass) end - aClass.__mixins[mixin] = true end local Object = { @@ -199,17 +198,6 @@ local Object = { assert(type(self) == 'table', "Make sure you that you are using 'Class:include' instead of 'Class.include'") for _,mixin in ipairs({...}) do _includeMixin(self, mixin) end return self - end, - - includes = function(self, mixin) - return type(mixin) == 'table' and - type(self) == 'table' and - type(self.__mixins) == 'table' and - ( self.__mixins[mixin] or - type(self.super) == 'table' and - type(self.super.includes) == 'function' and - self.super:includes(mixin) - ) end } } diff --git a/spec/default_methods_spec.lua b/spec/default_methods_spec.lua index 6f12bb6..875191f 100644 --- a/spec/default_methods_spec.lua +++ b/spec/default_methods_spec.lua @@ -260,73 +260,6 @@ describe('Default methods', function() end) end) - - describe('includes', function() - - describe('nils, numbers, etc', function() - local o = Object:new() - local primitives = {nil, 1, 'hello', {}, function() end} - - for _,primitive in pairs(primitives) do - local theType = type(primitive) - describe('A ' .. theType, function() - - local f1 = function() return Object.includes(Object, primitive) end - local f2 = function() return Object.includes(primitive, o) end - local f3 = function() return Object.includes(primitive, primitive) end - - - describe('don\'t throw errors', function() - it('includes(Object, '.. theType ..')', function() - assert.not_error(f1) - end) - it('includes(' .. theType .. ', Object:new())', function() - assert.not_error(f2) - end) - it('includes(' .. theType .. ',' .. theType ..')', function() - assert.not_error(f3) - end) - end) - - it('make includes return false', function() - assert.is_false(f1()) - assert.is_false(f2()) - assert.is_false(f3()) - end) - - end) - end -- for - - end) - - describe('A class', function() - - local Class1 = class('Class1') - local Class2 = class('Class2', Class1) - local Class3 = class('Class3', Class2) - local UnrelatedClass = class('Unrelated') - - local hasFoo = { foo=function() return 'foo' end } - Class1:include(hasFoo) - - it('returns true if it includes a mixin', function() - assert.is_true(Class1:includes(hasFoo)) - end) - - it('returns true if its superclass includes a mixin', function() - assert.is_true(Class2:includes(hasFoo)) - assert.is_true(Class3:includes(hasFoo)) - end) - - it('returns false otherwise', function() - assert.is_false(UnrelatedClass:includes(hasFoo)) - end) - - end) - - end) - - end)