Class: Yadriggy::ConstPathRef
- Includes:
- AstHelper
- Defined in:
- lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb
Overview
Constant path reference, such as Yadriggy::ConstPathRef
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Const
readonly
The class or module name.
-
#scope ⇒ ConstPathRef|Const
readonly
The scope.
Attributes inherited from ASTnode
Class Method Summary collapse
Instance Method Summary collapse
-
#accept(evaluator) ⇒ void
A method for Visitor pattern.
- #const_value ⇒ Object
- #const_value_in_class(clazz) ⇒ Object
-
#initialize(sexp) ⇒ ConstPathRef
constructor
A new instance of ConstPathRef.
- #value ⇒ Object
- #value_in_class(klass) ⇒ Object
Methods included from AstHelper
#has_tag?, #to_node, #to_nodes
Methods inherited from ASTnode
#add_child, #add_children, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string
Constructor Details
#initialize(sexp) ⇒ ConstPathRef
Returns a new instance of ConstPathRef.
565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/yadriggy/ast.rb', line 565 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 |
Instance Attribute Details
#name ⇒ Const (readonly)
Returns the class or module name.
561 562 563 |
# File 'lib/yadriggy/ast.rb', line 561 def name @name end |
#scope ⇒ ConstPathRef|Const (readonly)
Returns the scope.
558 559 560 |
# File 'lib/yadriggy/ast.rb', line 558 def scope @scope end |
Class Method Details
.tags ⇒ Object
563 |
# File 'lib/yadriggy/ast.rb', line 563 def self.() [:const_path_ref, :top_const_ref] end |
Instance Method Details
#accept(evaluator) ⇒ void
This method returns an undefined value.
A method for Visitor pattern.
580 581 582 |
# File 'lib/yadriggy/ast.rb', line 580 def accept(evaluator) evaluator.const_path_ref(self) end |
#const_value ⇒ Object
320 |
# File 'lib/yadriggy/ast_value.rb', line 320 def const_value() value end |
#const_value_in_class(clazz) ⇒ Object
322 323 324 |
# File 'lib/yadriggy/ast_value.rb', line 322 def const_value_in_class(clazz) value_in_class(clazz) end |
#value ⇒ Object
301 302 303 |
# File 'lib/yadriggy/ast_value.rb', line 301 def value() value_in_class(get_context_class) end |
#value_in_class(klass) ⇒ Object
305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
# 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 |