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
|
# File 'lib/ruby_less/signature_hash.rb', line 6
def [](signature)
if type = get(signature)
return type
elsif signature.kind_of?(Array)
size = signature.size
static_types = true
ancestors = signature.map do |k|
if k.kind_of?(Symbol)
[k]
elsif k.kind_of?(Class) && k.name != ''
k.ancestors
else
static_types = false
k.respond_to?(:ancestors) ? k.ancestors : [k]
end
end
each do |key, type|
next unless key.size == size
ok = true
key.each_with_index do |k, i|
if !ancestors[i].include?(k)
ok = false
break
end
end
if ok
self[signature] = type if static_types
return type
end
end
end
nil
end
|