Class: Red::DefinitionNode::InstanceMethodNode
- Inherits:
-
Object
- Object
- Red::DefinitionNode::InstanceMethodNode
- Defined in:
- lib/red/definition_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
- #compile_internals(options = {}) ⇒ Object
- #compile_node(options = {}) ⇒ Object
-
#initialize(function_name, scope) ⇒ InstanceMethodNode
constructor
A new instance of InstanceMethodNode.
Constructor Details
#initialize(function_name, scope) ⇒ InstanceMethodNode
Returns a new instance of InstanceMethodNode.
79 80 81 82 83 84 85 |
# File 'lib/red/definition_nodes.rb', line 79 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
98 99 100 101 102 103 |
# File 'lib/red/definition_nodes.rb', line 98 def compile_internals( = {}) 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
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/red/definition_nodes.rb', line 87 def compile_node( = {}) case false when [:as_attribute].nil? "this.%s = function(%s) { %s; }" when [:as_prototype].nil? "%s: function(%s) { %s; }" when !([:as_attribute].nil? && [:as_prototype].nil?) "function %s(%s) { %s; }" end % self.compile_internals end |