/
object.fnc
131 lines (103 loc) · 2.22 KB
/
object.fnc
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
127
128
129
130
131
def class Object {
"Root class of Fancy's class hierarchy. All classes inherit from Object."
def loop: block {
"Infinitely calls the block (loops)."
{ true } while_true: {
block call
}
}
def println {
"Same as Console println: self. Prints the object on STDOUT, followed by a newline."
Console println: self
}
def print {
"Same as Console print: self. Prints the object on STDOUT."
Console print: self
}
def != other {
"Indicates, if two objects are unequal."
self == other not
}
def if_false: block {
"Calls the block."
nil
}
def if_nil: block {
"Returns nil."
nil
}
def nil? {
"Returns nil."
nil
}
def false? {
"Returns nil."
nil
}
def true? {
"Returns nil."
nil
}
def if_do: block {
"If the object is non-nil, it calls the given block with itself as argument."
self nil? if_true: {
nil
} else: {
block call: [self]
}
}
def if_do: then_block else: else_block {
"""If the object is non-nil, it calls the given then_block with itself as argument.
Otherwise it calls the given else_block."""
self nil? if_true: {
else_block call
} else: {
then_block call: [self]
}
}
def or_take: other {
"Returns self if it's non-nil, otherwise returns the given object."
self nil? if_true: {
other
} else: {
self
}
}
def to_num {
0
}
def to_a {
[self]
}
def NATIVE is_a?: class_obj {
"Indicates, if an object is an instance of a given Class."
self class subclass?: class_obj
}
def || other {
"Same as Object#or:"
or: other
}
def && other {
"Same as Object#and:"
and: other
}
def if: cond then: block {
cond if_true: block
}
def if: cond then: then_block else: else_block {
cond if_true: then_block else: else_block
}
def while: cond_block do: body_block {
cond_block while_true: body_block
}
def until: cond_block do: body_block {
cond_block while_false: body_block
}
def unless: cond do: block {
cond if_false: block
}
def method: method_name {
"Returns a singleton method for self, if defined."
self metaclass method: method_name
}
}