masover-threadsafe 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/threadsafe.rb +30 -9
- metadata +1 -1
data/lib/threadsafe.rb
CHANGED
|
@@ -3,18 +3,39 @@
|
|
|
3
3
|
# (Otherwise, we'd either have to require them here, or intercept every
|
|
4
4
|
# require, which we can't do until autoload is fixed.)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
unsafe_classes = [
|
|
7
7
|
# Default to false
|
|
8
|
-
Object
|
|
9
|
-
|
|
8
|
+
Object
|
|
9
|
+
]
|
|
10
|
+
|
|
11
|
+
safe_classes = [
|
|
12
|
+
# Immutables
|
|
13
|
+
TrueClass,
|
|
14
|
+
FalseClass,
|
|
15
|
+
NilClass,
|
|
16
|
+
Symbol,
|
|
17
|
+
Numeric
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
# TODO: Are frozen strings safe? If so, what's the sanest implementation?
|
|
21
|
+
# Since #freeze and #frozen? seem to exist on Object, it can't be global.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Unrolled to avoid ugly evals or define_method overhead.
|
|
25
|
+
# It's simple enough anyway.
|
|
26
|
+
|
|
27
|
+
safe_classes.each do |klass|
|
|
28
|
+
klass.class_eval do
|
|
29
|
+
unless method_defined? :threadsafe?
|
|
30
|
+
def threadsafe?; true; end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
unsafe_classes.each do |klass|
|
|
10
36
|
klass.class_eval do
|
|
11
37
|
unless method_defined? :threadsafe?
|
|
12
|
-
|
|
13
|
-
if safe
|
|
14
|
-
def threadsafe?; true; end
|
|
15
|
-
else
|
|
16
|
-
def threadsafe?; false; end
|
|
17
|
-
end
|
|
38
|
+
def threadsafe?; false; end
|
|
18
39
|
end
|
|
19
40
|
end
|
|
20
41
|
end
|