Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::SelfToDictNameInAssignments

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

Overview

if inside ‘Foo’ class, transforms:

self.something = 1

to:

fooObj.something = 1

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 collapse

Attributes inherited from Riml::AST_Rewriter

#ast, #classes, #options

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, #max_recursion_lvl, #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

#initialize(dict_name) ⇒ SelfToDictNameInAssignments

Returns a new instance of SelfToDictNameInAssignments.



589
590
591
# File 'lib/riml/ast_rewriter.rb', line 589

def initialize(dict_name)
  @dict_name = dict_name
end

Instance Attribute Details

#dict_nameObject (readonly)

Returns the value of attribute dict_name.



588
589
590
# File 'lib/riml/ast_rewriter.rb', line 588

def dict_name
  @dict_name
end

Instance Method Details

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


593
594
595
# File 'lib/riml/ast_rewriter.rb', line 593

def match?(node)
  AssignNode === node && DictGetNode === node.lhs && node.lhs.dict.name == "self"
end

#replace(node) ⇒ Object



597
598
599
# File 'lib/riml/ast_rewriter.rb', line 597

def replace(node)
  node.lhs.dict.name = @dict_name
end