Class: Red::DefinitionNode::ClassMethodNode

Inherits:
Object
  • Object
show all
Defined in:
lib/red/definition_nodes.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(receiver, function_name, scope) ⇒ ClassMethodNode

Returns a new instance of ClassMethodNode.



53
54
55
56
57
# File 'lib/red/definition_nodes.rb', line 53

def initialize(receiver, function_name, scope)
  @receiver, @function_name = [receiver, function_name].build_nodes
  @arguments = (scope.assoc(:block).assoc(:args)[1..-1] || []).build_nodes
  @lines = (scope.assoc(:block)[2..-1] || []).build_nodes
end

Instance Method Details

#compile_internals(options = {}) ⇒ Object



70
71
72
73
74
75
# File 'lib/red/definition_nodes.rb', line 70

def compile_internals(options = {})
  function_name = @function_name.compile_node
  arguments = @arguments.compile_nodes.join(', ')
  lines = @lines.compile_nodes.compact.join('; ')
  return [function_name, arguments, lines]
end

#compile_node(options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/red/definition_nodes.rb', line 59

def compile_node(options = {})
  case false
  when options[:as_attribute].nil?
    "this.%s = function(%s) { %s; }"
  when options[:as_prototype].nil?
    "%s: function(%s) { %s; }"
  when !(options[:as_attribute].nil? && options[:as_prototype].nil?)
    "function %s(%s) { %s; }"
  end % self.compile_internals
end