Skip to content

Commit e6eac77

Browse files
committed
Improve handling of global variables.
1 parent e54e1dc commit e6eac77

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

globals.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,32 @@ def initialize
44
@global_functions = {}
55
end
66

7+
def keys
8+
@global_functions.keys
9+
end
10+
711
# Returns the actual name
812
def set(fname, function)
913
suffix = ""
1014
i = 0
11-
while @global_functions[fname + suffix]
12-
i += 1
13-
suffix = "__#{i}"
15+
if @global_functions[fname]
16+
while @global_functions[fname + suffix]
17+
i += 1
18+
suffix = "__#{i}"
19+
end
20+
fname = fname + suffix
1421
end
15-
fname = fname + suffix
1622

1723
# add the method to the global list of functions defined so far
1824
# with its "munged" name.
1925
@global_functions[fname] = function
2026
fname
2127
end
2228

29+
def [] name
30+
@global_functions[name]
31+
end
32+
2333
# We on purpose provide this instead of "each"
2434
# as the use-case we need is function/method
2535
# compilation where additional synthesized methods

0 commit comments

Comments
 (0)