class Yadriggy::ConstPathRef

Constant path reference, such as `Yadriggy::ConstPathRef`.

Attributes

name[R]

@return [Const] the class or module name.

scope[R]

@return [ConstPathRef|Const] the scope.

Public Class Methods

new(sexp) click to toggle source
# File lib/yadriggy/ast.rb, line 561
def initialize(sexp)
  if sexp[0] == :const_path_ref || sexp[0] == :const_path_field
    @scope = to_node(sexp[1])
    @name = to_node(has_tag?(sexp[2], :@const))
    add_child(@scope)
  else
    @scope = nil
    @name = to_node(has_tag?(sexp[1], :@const))
  end
  add_child(@name)
end
tags() click to toggle source
# File lib/yadriggy/ast.rb, line 559
def self.tags() [:const_path_ref, :top_const_ref] end

Public Instance Methods

accept(evaluator) click to toggle source

A method for Visitor pattern. @param [Eval] evaluator the visitor of Visitor pattern. @return [void]

# File lib/yadriggy/ast.rb, line 576
def accept(evaluator)
  evaluator.const_path_ref(self)
end
const_value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 320
def const_value() value end
const_value_in_class(clazz) click to toggle source
# File lib/yadriggy/ast_value.rb, line 322
def const_value_in_class(clazz)
  value_in_class(clazz)
end
value() click to toggle source
# File lib/yadriggy/ast_value.rb, line 301
def value()
  value_in_class(get_context_class)
end
value_in_class(klass) click to toggle source
# File lib/yadriggy/ast_value.rb, line 305
def value_in_class(klass)
  if scope.nil?
    clazz = Object
  else
    clazz = scope.value_in_class(klass)
    return Undef if clazz == Undef
  end

  unless clazz.is_a?(Module)
    raise "unknown scope #{scope.class.name} #{clazz&.to_s || 'nil'}"
  end

  name.value_in_class(clazz)
end