Class: Red::DefinitionNode::InstanceMethodNode

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(function_name, scope) ⇒ InstanceMethodNode

Returns a new instance of InstanceMethodNode.



108
109
110
111
112
113
114
# File 'lib/red/definition_nodes.rb', line 108

def initialize(function_name, scope)
  block = scope.assoc(:block)
  @@rescue_is_safe = (block[2].first == :rescue)
  @function_name = (function_name == :function ? nil : function_name).build_node
  @arguments = (block.assoc(:args)[1..-1] || []).build_nodes
  @lines = (block[2..-1] || []).build_nodes
end

Instance Method Details

#compile_internals(options = {}) ⇒ Object



127
128
129
130
131
132
# File 'lib/red/definition_nodes.rb', line 127

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



116
117
118
119
120
121
122
123
124
125
# File 'lib/red/definition_nodes.rb', line 116

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