-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuiltins.rb
51 lines (44 loc) · 1017 Bytes
/
builtins.rb
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
# Built in functions for strings
module StringFuncs
def self.times(string, x)
string * x
end
end
# Built in function for arrays
module ArrayFuncs
def self.includes(array, element)
array.include? element
end
def self.append(array, element)
array << element
end
end
# Built in functions in the global scope
module GeneralFuncs
def self.p(*args)
print(*args)
end
def self.pl(*args)
puts(*args)
end
end
# Built in functions for hashes
module HashFuncs
def self.has_key(hash, element)
hash.key? element
end
end
module IntegerFuncs
def self.is_even(int)
int.even?
end
end
module Builtins
General = { 'p' => GeneralFuncs.method(:p),
'pl' => GeneralFuncs.method(:pl) }
String = { 'times' => StringFuncs.method(:times) }
Array = { 'includes' => ArrayFuncs.method(:includes),
'append' => ArrayFuncs.method(:append)}
Hash = { 'has_key' => HashFuncs.method(:has_key) }
Fixnum = { 'is_even' => IntegerFuncs.method(:is_even) }
end