mirror of
https://github.com/kikito/middleclass.git
synced 2024-11-08 09:34:22 +00:00
made class non-global
This commit is contained in:
parent
491eb44628
commit
88e84d13c2
@ -135,11 +135,6 @@ function Object:initialize() end
|
||||
|
||||
function Object:__tostring() return "instance of " .. tostring(self.class) end
|
||||
|
||||
function class(name, super, ...)
|
||||
super = super or Object
|
||||
return super:subclass(name, ...)
|
||||
end
|
||||
|
||||
function instanceOf(aClass, obj)
|
||||
if type(aClass) ~= 'table' or type(obj) ~= 'table' or not obj.class then return false end
|
||||
if obj.class == aClass then return true end
|
||||
@ -157,4 +152,11 @@ function includes(mixin, aClass)
|
||||
return includes(mixin, aClass.super)
|
||||
end
|
||||
|
||||
function middleclass.class(name, super, ...)
|
||||
super = super or Object
|
||||
return super:subclass(name, ...)
|
||||
end
|
||||
|
||||
setmetatable(middleclass, { __call = function(_, ...) return middleclass.class(...) end })
|
||||
|
||||
return middleclass
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('Object', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('class()', function()
|
||||
|
||||
@ -9,30 +9,18 @@ context('class()', function()
|
||||
end)
|
||||
|
||||
context('when given a name', function()
|
||||
local TheClass
|
||||
|
||||
before(function()
|
||||
TheClass = class('TheClass')
|
||||
end)
|
||||
|
||||
test('the resulting class has the correct name', function()
|
||||
test('the resulting class has the correct name and Object as its superclass', function()
|
||||
local TheClass = class('TheClass')
|
||||
assert_equal(TheClass.name, 'TheClass')
|
||||
end)
|
||||
|
||||
test('the resulting class has Object as its superclass', function()
|
||||
assert_equal(TheClass.super, Object)
|
||||
end)
|
||||
end)
|
||||
|
||||
context('when given a name and a superclass', function()
|
||||
test('the resulting class has the correct name and superclass', function()
|
||||
local TheSuperClass = class('TheSuperClass')
|
||||
local TheSubClass = class('TheSubClass', TheSuperClass)
|
||||
|
||||
test('the resulting class has the correct name', function()
|
||||
assert_equal(TheSubClass.name, 'TheSubClass')
|
||||
end)
|
||||
|
||||
test('the resulting class has the correct superclass', function()
|
||||
assert_equal(TheSubClass.super, TheSuperClass)
|
||||
end)
|
||||
end)
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('A Class', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('includes', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('instanceOf', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('An instance', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('Metamethods', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('A Mixin', function()
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
require 'middleclass'
|
||||
local class = require 'middleclass'
|
||||
|
||||
context('subclassOf', function()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user