Repository navigation
Expand file tree
/
Copy pathpull4.moon
More file actions
126 lines (90 loc) · 2.55 KB
/
Copy pathpull4.moon
File metadata and controls
126 lines (90 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--Pull number 4
--Testing classes and super methods continued
--Super methods here are very confusing. I read the documentation
--3 times to understand all unique cases
--These are the cases that I could identify as unique for using super
class Nums
_count: 111
counter: => @_count
class eightNums extends Nums
counter: => "%08d"\format super!
instance = eightNums!
print assert instance\counter! == "00000111"
class Base
_count: 111
counter: =>
@_count
class Thing extends Base
other_method: => super\counter!
--Should take method from super, 111
instance = Thing!
print assert instance\other_method! == 111
--The super class method belongs to Page, not words.
--Has to do with inheritance and the extension
class Page
class Words extends Page
get_super: => super
instance = Words!
print assert instance\get_super! == Page
class Foo
count: 1
get_count: => @count
class Bar extends Foo
get_count: => "this is wrong"
get_method: => super\get_count
instance = Bar!
--the Double exclamation point I do not understand fully.
--if one exclamation is left result is a pointer to the function
print assert instance\get_method!! == 1
class SuperBase
@cons: "super cons"
cons: "base cons"
--Base should take on the super constructor in SuperBase
class Base extends SuperBase
print assert "super cons"== Base.cons
--Similar Test, but without base and super method
class Hello
prop: "world"
class Goodbye extends Hello
--Goodbye should inherit everything from Hello
print assert "world"== Goodbye.prop
--Calling this one a trickle down, not the official name
--Testing to see if methods trace back up
class One
@a: =>
1
-- Expecting 1 + 2
class Two extends One
@a: =>
super! + 2
-- should be 1 + 2 + 3 because super! calls from two.
class Three extends Two
@a: =>
super! + 3
class Four extends Three
@a: =>
super! + 4
print assert Four\a! == 10
--Dealing with parent classes and overwriting constructors
class Foo
@value: "foo"
num: => 1205
char: => "a"
class Bar
@value: "bar"
num: => 0131
char: => "b"
class Bass extends Foo
num: =>
super! + 1
get_super: =>
super
instance = Bass!
print assert "a" == instance\char!
print assert 1206 == instance\num!
print assert Foo == instance\get_super!
Bass.__parent = Bar
setmetatable Bass.__base, Bar.__base
print assert "b" == instance\char!
print assert 0132 == instance\num!
print assert Bar == instance\get_super!