Class: Riml::AST_Rewriter::TopLevelDefMethodToDef

Inherits:
Riml::AST_Rewriter 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, #recursive?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match

Constructor Details

This class inherits a constructor from Riml::AST_Rewriter

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


631
632
633
# File 'lib/ast_rewriter.rb', line 631

def match?(node)
  DefMethodNode === node
end

#replace(node) ⇒ Object



635
636
637
638
639
640
641
642
643
644
# File 'lib/ast_rewriter.rb', line 635

def replace(node)
  Riml.warn "top-level function #{node.full_name} is defined with 'defm', which " \
    "should only be used inside classes. Please use 'def'"
  scope_modifier = node.scope_modifier
  keywords = node.keywords
  new_node = node.to_def_node
  new_node.scope_modifier = scope_modifier
  new_node.keywords = keywords
  node.replace_with(new_node)
end