Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::InsertInitializeMethod
- Inherits:
-
Riml::AST_Rewriter
- Object
- Riml::AST_Rewriter
- Riml::AST_Rewriter::ClassDefinitionToFunctions::InsertInitializeMethod
- Defined in:
- lib/riml/ast_rewriter.rb
Constant Summary
Constants included from Constants
Constants::BUILTIN_COMMANDS, Constants::BUILTIN_FUNCTIONS, Constants::COMPARISON_OPERATORS, Constants::COMPILED_STRING_LOCATION, Constants::DEFINE_KEYWORDS, Constants::END_KEYWORDS, Constants::IGNORECASE_CAPABLE_OPERATORS, Constants::KEYWORDS, Constants::REGISTERS, Constants::RIML_CLASS_COMMANDS, Constants::RIML_COMMANDS, Constants::RIML_END_KEYWORDS, Constants::RIML_FILE_COMMANDS, Constants::RIML_KEYWORDS, Constants::SPECIAL_VARIABLE_PREFIXES, Constants::SPLAT_LITERAL, Constants::UNKNOWN_LOCATION_INFO, Constants::VIML_COMMANDS, Constants::VIML_END_KEYWORDS, Constants::VIML_KEYWORDS
Instance Attribute Summary
Attributes inherited from Riml::AST_Rewriter
Instance Method Summary collapse
- #imported_superclass? ⇒ Boolean
-
#match?(class_node) ⇒ Boolean
if doesn’t have an initialize method, put one at the beginning of the class definition.
- #max_recursion_lvl ⇒ Object
- #replace(class_node) ⇒ Object
- #superclass_params ⇒ Object
Methods inherited from Riml::AST_Rewriter
#add_SID_function!, #add_SID_function?, #do_establish_parents, #do_rewrite_on_match, #establish_parents, #initialize, #reorder_includes_based_on_class_dependencies!, #resolve_class_dependencies!, #resolve_class_dependencies?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match, #watch_for_class_pickup
Constructor Details
This class inherits a constructor from Riml::AST_Rewriter
Instance Method Details
#imported_superclass? ⇒ Boolean
653 654 655 |
# File 'lib/riml/ast_rewriter.rb', line 653 def imported_superclass? classes.superclass(ast.full_name).imported? end |
#match?(class_node) ⇒ Boolean
if doesn’t have an initialize method, put one at the beginning of the class definition
625 626 627 |
# File 'lib/riml/ast_rewriter.rb', line 625 def match?(class_node) ClassDefinitionNode === class_node && class_node.constructor.nil? end |
#max_recursion_lvl ⇒ Object
657 658 659 |
# File 'lib/riml/ast_rewriter.rb', line 657 def max_recursion_lvl 1 end |
#replace(class_node) ⇒ Object
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 |
# File 'lib/riml/ast_rewriter.rb', line 629 def replace(class_node) if class_node.superclass? && !imported_superclass? def_node = DefNode.new( '!', nil, nil, "initialize", superclass_params, nil, Nodes.new([SuperNode.new([], false)]) ) # has imported superclass and no initialize method. Must create # initialize method taking *splat parameter and call super with it elsif class_node.superclass? def_node = DefNode.new( '!', nil, nil, "initialize", ['...'], nil, Nodes.new([SuperNode.new([SplatNode.new(GetVariableNode.new('a:', '000'))], false)]) ) else def_node = DefNode.new( '!', nil, nil, "initialize", [], nil, Nodes.new([]) ) end class_node.expressions.nodes.unshift(def_node) reestablish_parents(class_node) end |
#superclass_params ⇒ Object
649 650 651 |
# File 'lib/riml/ast_rewriter.rb', line 649 def superclass_params classes.superclass(ast.full_name).constructor.parameters end |