Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::InsertInitializeMethod

Inherits:
Riml::AST_Rewriter
  • Object
show all
Defined in:
lib/ast_rewriter.rb

Constant Summary

Constants included from Constants

Constants::BUILTIN_COMMANDS, Constants::BUILTIN_FUNCTIONS, Constants::COMPARISON_OPERATORS, Constants::DEFINE_KEYWORDS, Constants::END_KEYWORDS, Constants::IGNORECASE_CAPABLE_OPERATORS, Constants::KEYWORDS, Constants::REGISTERS, Constants::RIML_COMMANDS, Constants::RIML_END_KEYWORDS, Constants::RIML_KEYWORDS, Constants::SPECIAL_VARIABLE_PREFIXES, Constants::SPLAT_LITERAL, Constants::VIML_COMMANDS, Constants::VIML_END_KEYWORDS, Constants::VIML_KEYWORDS

Instance Attribute Summary

Attributes inherited from Riml::AST_Rewriter

#ast, #classes, #rewritten_included_and_sourced_files

Instance Method Summary collapse

Methods inherited from Riml::AST_Rewriter

#add_SID_function!, #add_SID_function?, #do_establish_parents, #do_rewrite_on_match, #establish_parents, #initialize, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match

Constructor Details

This class inherits a constructor from Riml::AST_Rewriter

Instance Method Details

#match?(class_node) ⇒ Boolean

if doesn’t have an initialize method, put one at the beginning of the class definition

Returns:

  • (Boolean)


377
378
379
# File 'lib/ast_rewriter.rb', line 377

def match?(class_node)
  ClassDefinitionNode === class_node && class_node.constructor.nil?
end

#recursive?Boolean

Returns:

  • (Boolean)


399
400
401
# File 'lib/ast_rewriter.rb', line 399

def recursive?
  false
end

#replace(class_node) ⇒ Object



381
382
383
384
385
386
387
388
389
390
391
392
393
# File 'lib/ast_rewriter.rb', line 381

def replace(class_node)
  if class_node.superclass?
    def_node = DefNode.new(
      '!', nil, nil, "initialize", superclass_params, nil, Nodes.new([SuperNode.new([], false)])
    )
  else
    def_node = DefNode.new(
      '!', nil, nil, "initialize", [], nil, Nodes.new([])
    )
  end
  class_node.expressions.unshift(def_node)
  reestablish_parents(class_node)
end

#superclass_paramsObject



395
396
397
# File 'lib/ast_rewriter.rb', line 395

def superclass_params
  classes.superclass(ast.full_name).constructor.parameters
end