jtor-stdlib 0.1.3-java → 0.1.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jtor-stdlib/base.rb +21 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 788765015218496bf8ce81d2ed3838276ac4d3ae
|
4
|
+
data.tar.gz: 9fdc417d377720e73b8e422b738b55a8ae7aa8ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fb439909e96c479f34295bd0cd9aa8809ed0ed668387ac7359c31016297ddc4887a3ba132b151300ecd33ed25fae9abdd0a29a12cf3cd001665e12fff086281
|
7
|
+
data.tar.gz: 3fd35e1e3689304d0bb4c6f371a3541c81da6f34a4559ae6e2c05398d635e3896e0ce53d7de1da341fd55a11b8757224beac7844b5dbea2a76d8524185b7f09a
|
data/lib/jtor-stdlib/base.rb
CHANGED
@@ -14,6 +14,10 @@ module Jtor
|
|
14
14
|
@_lookup_table ||= {}
|
15
15
|
end
|
16
16
|
|
17
|
+
def _lookup_table_static
|
18
|
+
@_lookup_table_static ||= {}
|
19
|
+
end
|
20
|
+
|
17
21
|
def _constructor_calls
|
18
22
|
@_constructor_calls ||= {}
|
19
23
|
end
|
@@ -21,16 +25,25 @@ module Jtor
|
|
21
25
|
# Method overloading is not a ruby thing, so we implement a pseudo-lookup
|
22
26
|
# mechanism for method based on the type/count of their args
|
23
27
|
def add_java_method(name, param_types, &block)
|
24
|
-
previously_defined = _lookup_table
|
25
|
-
|
28
|
+
previously_defined = add_method_to_lookup(_lookup_table, name,
|
29
|
+
param_types, &block)
|
26
30
|
return if previously_defined
|
27
31
|
define_method(name) do |*args|
|
28
32
|
instance_exec(*args, &self.class.lookup(name, *args))
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
36
|
+
def add_static_java_method(name, param_types, &block)
|
37
|
+
previously_defined = add_method_to_lookup(_lookup_table_static, name,
|
38
|
+
param_types, &block)
|
39
|
+
return if previously_defined
|
40
|
+
define_singleton_method(name) do |*args|
|
41
|
+
instance_exec(*args, &lookup(name, *args))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
32
45
|
def add_java_constructor(param_types, constructor_call = nil, &block)
|
33
|
-
add_method_to_lookup(:initialize, param_types, &block)
|
46
|
+
add_method_to_lookup(_lookup_table, :initialize, param_types, &block)
|
34
47
|
previously_defined = _constructor_calls.any?
|
35
48
|
_constructor_calls[param_types] = constructor_call
|
36
49
|
return if previously_defined
|
@@ -72,9 +85,11 @@ module Jtor
|
|
72
85
|
true
|
73
86
|
end
|
74
87
|
|
75
|
-
def add_method_to_lookup(name, param_types, &block)
|
76
|
-
|
77
|
-
|
88
|
+
def add_method_to_lookup(lookup_table, name, param_types, &block)
|
89
|
+
previously_defined = lookup_table[name]
|
90
|
+
lookup_table[name] ||= {}
|
91
|
+
lookup_table[name][param_types] = block
|
92
|
+
previously_defined
|
78
93
|
end
|
79
94
|
end
|
80
95
|
end
|