26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/yoda/parsing/scopes/builder.rb', line 26
def build(node, scope)
return if !node || !node.is_a?(AST::Vnode)
case node.type
when :def
mscope = MethodDefinition.new(node, scope)
scope.method_definitions << mscope
mscope.body_nodes.each { |node| build(node, mscope)}
when :defs
mscope = SingletonMethodDefinition.new(node, scope)
scope.method_definitions << mscope
mscope.body_nodes.each { |node| build(node, mscope)}
when :class
cscope = ClassDefinition.new(node, scope)
scope.child_scopes << cscope
cscope.body_nodes.each { |node| build(node, cscope)}
when :sclass
cscope = SingletonClassDefinition.new(node, scope)
scope.child_scopes << cscope
cscope.body_nodes.each { |node| build(node, cscope)}
when :module
mscope = ModuleDefinition.new(node, scope)
scope.child_scopes << mscope
mscope.body_nodes.each { |node| build(node, mscope)}
when :begin, :kwbegin, :block
node.children.each { |node| build(node, scope) }
else
if node.respond_to?(:children)
node.children.map { |node| build(node, scope) }
end
end
end
|