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.



1622
1623
1624
1625
1626
# File 'lib/yadriggy/ast.rb', line 1622

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:



1616
1617
1618
# File 'lib/yadriggy/ast.rb', line 1616

def body
  @body
end

#nameConst|ConstPathRef (readonly)

Returns the module name.

Returns:



1614
1615
1616
# File 'lib/yadriggy/ast.rb', line 1614

def name
  @name
end

#rescueRescue|nil (readonly)

Returns the rescue clause.

Returns:

  • (Rescue|nil)

    the rescue clause.



1618
1619
1620
# File 'lib/yadriggy/ast.rb', line 1618

def rescue
  @rescue
end

Class Method Details

.tagObject



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

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.



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

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

#initialize_body(bodystmt) ⇒ Object



1628
1629
1630
1631
1632
1633
# File 'lib/yadriggy/ast.rb', line 1628

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