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.



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

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:



1632
1633
1634
# File 'lib/yadriggy/ast.rb', line 1632

def body
  @body
end

#nameConst|ConstPathRef (readonly)

Returns the module name.

Returns:



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

def name
  @name
end

#rescueRescue|nil (readonly)

Returns the rescue clause.

Returns:

  • (Rescue|nil)

    the rescue clause.



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

def rescue
  @rescue
end

Class Method Details

.tagObject



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

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.



1654
1655
1656
# File 'lib/yadriggy/ast.rb', line 1654

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

#initialize_body(bodystmt) ⇒ Object



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

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