Class: Yadriggy::ModuleDef

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

Overview

Module definition.

Direct Known Subclasses

ClassDef, SingularClassDef

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, #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) ⇒ ModuleDef

Returns a new instance of ModuleDef.



1642
1643
1644
1645
1646
# File 'lib/yadriggy/ast.rb', line 1642

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

Instance Attribute Details

#bodyExprs|ASTnode (readonly)

Returns the body.

Returns:



1636
1637
1638
# File 'lib/yadriggy/ast.rb', line 1636

def body
  @body
end

#nameConst|ConstPathRef (readonly)

Returns the module name.

Returns:



1634
1635
1636
# File 'lib/yadriggy/ast.rb', line 1634

def name
  @name
end

#rescueRescue|nil (readonly)

Returns the rescue clause.

Returns:

  • (Rescue|nil)

    the rescue clause.



1638
1639
1640
# File 'lib/yadriggy/ast.rb', line 1638

def rescue
  @rescue
end

Class Method Details

.tagObject



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

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



1658
1659
1660
# File 'lib/yadriggy/ast.rb', line 1658

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

#initialize_body(bodystmt) ⇒ Object



1648
1649
1650
1651
1652
1653
# File 'lib/yadriggy/ast.rb', line 1648

def initialize_body(bodystmt)
  @body = Exprs.make(bodystmt[1] - [[:void_stmt]])
  @rescue = Rescue.make(bodystmt[2], bodystmt[3], bodystmt[4])
  add_child(@body)
  add_child(@rescue)
end