Class: Yadriggy::ConstPathRef

Inherits:
ASTnode
  • Object
show all
Includes:
AstHelper
Defined in:
lib/yadriggy/ast.rb,
lib/yadriggy/ast_value.rb

Overview

Constant path reference, such as Yadriggy::ConstPathRef.

Direct Known Subclasses

ConstPathField

Instance Attribute Summary collapse

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

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

#nameConst (readonly)

Returns the class or module name.

Returns:

  • (Const)

    the class or module name.



561
562
563
# File 'lib/yadriggy/ast.rb', line 561

def name
  @name
end

#scopeConstPathRef|Const (readonly)

Returns the scope.

Returns:



558
559
560
# File 'lib/yadriggy/ast.rb', line 558

def scope
  @scope
end

Class Method Details

.tagsObject



563
# File 'lib/yadriggy/ast.rb', line 563

def self.tags() [:const_path_ref, :top_const_ref] end

Instance Method Details

#accept(evaluator) ⇒ void

This method returns an undefined value.

A method for Visitor pattern.

Parameters:

  • evaluator (Eval)

    the visitor of Visitor pattern.



580
581
582
# File 'lib/yadriggy/ast.rb', line 580

def accept(evaluator)
  evaluator.const_path_ref(self)
end

#const_valueObject



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

#valueObject



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