Class: Yadriggy::ClassDef

Inherits:
ModuleDef show all
Defined in:
lib/yadriggy/ast.rb

Overview

Class definition.

Instance Attribute Summary collapse

Attributes inherited from ModuleDef

#body, #name, #rescue

Attributes inherited from ASTnode

#parent, #usertype

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ModuleDef

#initialize_body

Methods included from AstHelper

#has_tag?, #to_node, #to_nodes

Methods inherited from ASTnode

#add_child, #add_children, #const_value, #const_value_in_class, #get_context_class, #get_receiver_object, #is_proc?, #pretty_print, #root, #source_location, #source_location_string, #value, #value_in_class

Constructor Details

#initialize(sexp) ⇒ ClassDef

Returns a new instance of ClassDef.



1651
1652
1653
1654
1655
1656
1657
# File 'lib/yadriggy/ast.rb', line 1651

def initialize(sexp)
  @name = to_node(sexp[1])  # Const or ConstPathRef
  add_child(@name)
  @superclass = to_node(sexp[2])
  add_child(@superclass)
  initialize_body(has_tag?(sexp[3], :bodystmt))
end

Instance Attribute Details

#superclassASTnode|nil (readonly)

Returns the super class.

Returns:

  • (ASTnode|nil)

    the super class.



1647
1648
1649
# File 'lib/yadriggy/ast.rb', line 1647

def superclass
  @superclass
end

Class Method Details

.tagObject



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

def self.tag() :class 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.



1662
1663
1664
# File 'lib/yadriggy/ast.rb', line 1662

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