katakata_irb 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/katakata_irb/scope.rb +3 -0
- data/lib/katakata_irb/types.rb +14 -17
- data/lib/katakata_irb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03e0f334a22895540f29f3bb27551bff9bfcbede5aac767559006edbc77118f
|
4
|
+
data.tar.gz: 4db442409ca2ac1d853b4e7675ff3ac10aed0d6ced431d1abdbe2eea7a1fa298
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb7d8eae8b68d497c6e0c5c0d9bc8d8455d5af5638fb680b3048166188a1035a2e36229a7555203de4f8d18bc3089b92f441f496d6e2a074ad61587805b6de82
|
7
|
+
data.tar.gz: 75ef2f2f26505c98e3550342493474f47f11623fd1342f0529249e6e902e95f5ebf03f5053974c6813beee3697c0d13cb5a0adec073c65ece35dce9a3e3f01ed
|
data/Gemfile.lock
CHANGED
data/lib/katakata_irb/scope.rb
CHANGED
@@ -14,6 +14,7 @@ module KatakataIrb
|
|
14
14
|
@binding, @self_object = binding, self_object
|
15
15
|
@cache = { SELF => KatakataIrb::Types.type_from_object(self_object) }
|
16
16
|
@local_variables = binding.local_variables.map(&:to_s).to_set
|
17
|
+
@global_variables = global_variables.map(&:to_s).to_set
|
17
18
|
end
|
18
19
|
|
19
20
|
def level() = 0
|
@@ -36,6 +37,8 @@ module KatakataIrb
|
|
36
37
|
BaseScope.type_of(fallback: fallback) { @binding.local_variable_get(name) }
|
37
38
|
when :const
|
38
39
|
BaseScope.type_of(fallback: fallback) { @binding.eval name }
|
40
|
+
when :gvar
|
41
|
+
BaseScope.type_of(fallback: fallback) { @binding.eval name if @global_variables.include? name }
|
39
42
|
end
|
40
43
|
)
|
41
44
|
end
|
data/lib/katakata_irb/types.rb
CHANGED
@@ -95,15 +95,11 @@ module KatakataIrb::Types
|
|
95
95
|
given << UnionType[*centers.drop(opts.size)]
|
96
96
|
expected << rest.type
|
97
97
|
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
0.5
|
104
|
-
else
|
105
|
-
0
|
106
|
-
end
|
98
|
+
if given.any?
|
99
|
+
score += given.zip(expected).count do |t, e|
|
100
|
+
e = from_rbs_type e, receiver_type
|
101
|
+
intersect?(t, e) || (intersect?(STRING, e) && t.methods.include?(:to_str)) || (intersect?(INTEGER, e) && t.methods.include?(:to_int)) || (intersect?(ARRAY, e) && t.methods.include?(:to_ary))
|
102
|
+
end.fdiv(given.size)
|
107
103
|
end
|
108
104
|
end
|
109
105
|
[[method_type, given || [], expected || []], score]
|
@@ -114,15 +110,16 @@ module KatakataIrb::Types
|
|
114
110
|
end
|
115
111
|
|
116
112
|
def self.intersect?(a, b)
|
117
|
-
atypes =
|
118
|
-
btypes =
|
119
|
-
intersect = ->(type, &block) do
|
120
|
-
aa, bb = [atypes, btypes].map {|types| (types[type] || []).map(&block) }
|
121
|
-
(aa & bb).any?
|
122
|
-
end
|
113
|
+
atypes = a.types.group_by(&:class)
|
114
|
+
btypes = b.types.group_by(&:class)
|
123
115
|
return true if atypes[ProcType] && btypes[ProcType]
|
124
|
-
|
125
|
-
|
116
|
+
if atypes[SingletonType] && btypes[SingletonType]
|
117
|
+
aa, bb = [atypes, btypes].map {|types| types[SingletonType].map(&:module_or_class) }
|
118
|
+
return true if (aa & bb).any?
|
119
|
+
end
|
120
|
+
|
121
|
+
aa, bb = [atypes, btypes].map {|types| (types[InstanceType] || []).map(&:klass) }
|
122
|
+
(aa.flat_map(&:ancestors) & bb).any?
|
126
123
|
end
|
127
124
|
|
128
125
|
def self.type_from_object(object)
|
data/lib/katakata_irb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: katakata_irb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tompng
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: irb
|