class Yoda::Parsing::Scopes::Builder
Attributes
node[R]
@return [AST::Node]
Public Class Methods
new(node)
click to toggle source
@param node [AST::Node]
# File lib/yoda/parsing/scopes/builder.rb, line 9 def initialize(node) @node = node @root_scope = Root.new(node) end
Public Instance Methods
build(node, scope)
click to toggle source
@param node [AST::Node] @param scope [Base] @return [void]
# File lib/yoda/parsing/scopes/builder.rb, line 26 def build(node, scope) return if !node || !node.is_a?(AST::Node) 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
root_scope()
click to toggle source
@return [Scope]
# File lib/yoda/parsing/scopes/builder.rb, line 15 def root_scope unless @did_build @did_build = true build(node, @root_scope) end @root_scope end