Class: Riml::AST_Rewriter::ClassDefinitionToFunctions::SelfToObjArgumentInPrivateFunction
- Inherits:
-
Riml::AST_Rewriter
- Object
- Riml::AST_Rewriter
- Riml::AST_Rewriter::ClassDefinitionToFunctions::SelfToObjArgumentInPrivateFunction
- 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
-
#initialize(ast, classes, class_node) ⇒ SelfToObjArgumentInPrivateFunction
constructor
A new instance of SelfToObjArgumentInPrivateFunction.
- #match?(node) ⇒ Boolean
- #replace(node) ⇒ Object
Methods inherited from Riml::AST_Rewriter
#add_SID_function!, #add_SID_function?, #do_establish_parents, #do_rewrite_on_match, #establish_parents, #recursive?, #rewrite, #rewrite_included_and_sourced_files!, #rewrite_on_match
Constructor Details
#initialize(ast, classes, class_node) ⇒ SelfToObjArgumentInPrivateFunction
Returns a new instance of SelfToObjArgumentInPrivateFunction.
237 238 239 240 |
# File 'lib/ast_rewriter.rb', line 237 def initialize(ast, classes, class_node) super(ast, classes) @class_node = class_node end |
Instance Method Details
#match?(node) ⇒ Boolean
242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/ast_rewriter.rb', line 242 def match?(node) return unless GetVariableNode === node && node.scope_modifier == nil && node.name == 'self' return if node.parent.is_a?(DictGetDotNode) && node.parent.parent.is_a?(CallNode) && (@class_node.private_function_names & node.parent.keys).size == 1 # make sure we're not nested in a different function n = node until n.instance_of?(DefNode) n = n.parent end n == ast end |
#replace(node) ⇒ Object
254 255 256 257 |
# File 'lib/ast_rewriter.rb', line 254 def replace(node) node.name = @class_node.constructor_obj_name node.scope_modifier = 'a:' end |