class Riml::AST_Rewriter::ClassDefinitionToFunctions

Public Instance Methods

match?(node) click to toggle source
# File lib/riml/ast_rewriter.rb, line 395
def match?(node)
  ClassDefinitionNode === node
end
max_recursion_lvl() click to toggle source
# File lib/riml/ast_rewriter.rb, line 429
def max_recursion_lvl
  1
end
replace(node) click to toggle source
# File lib/riml/ast_rewriter.rb, line 399
def replace(node)
  classes[node.full_name] = node

  RegisterPrivateFunctions.new(node.expressions, classes).rewrite_on_match
  DefNodeToPrivateFunction.new(node.expressions, classes).rewrite_on_match
  InsertInitializeMethod.new(node, classes).rewrite_on_match
  constructor = node.constructor
  constructor.name = node.constructor_name
  constructor.original_name = 'initialize'
  constructor.scope_modifier = node.scope_modifier
  # set up dictionary variable at top of function
  dict_name = node.constructor_obj_name
  constructor.expressions.nodes.unshift(
    AssignNode.new('=', GetVariableNode.new(nil, dict_name), DictionaryNode.new({}))
  )

  InitializeSuperToObjectExtension.new(constructor, classes, node).rewrite_on_match
  ExtendObjectWithMethods.new(node, classes).rewrite_on_match
  SelfToDictNameInAssignments.new(dict_name).rewrite_on_match(constructor)
  SuperToSuperclassFunction.new(node, classes).rewrite_on_match
  PrivateFunctionCallToPassObjExplicitly.new(node, classes).rewrite_on_match
  SplatsToCallFunctionInCallingContext.new(node, classes).rewrite_on_match
  SelfToDictName.new(dict_name).rewrite_on_match(constructor)

  constructor.expressions.nodes.push(
    ReturnNode.new(GetVariableNode.new(nil, dict_name))
  )
  reestablish_parents(constructor)
end