Class: Red::AssignmentNode::AttributeNode
- Inherits:
-
Object
- Object
- Red::AssignmentNode::AttributeNode
- Defined in:
- lib/red/assignment_nodes.rb
Overview
:nodoc:
Instance Method Summary collapse
- #compile_internals(options = {}) ⇒ Object
- #compile_node(options = {}) ⇒ Object
- #compile_receiver(variable_name, slot) ⇒ Object
-
#initialize(variable_name, slot_equals, arguments) ⇒ AttributeNode
constructor
A new instance of AttributeNode.
Constructor Details
#initialize(variable_name, slot_equals, arguments) ⇒ AttributeNode
Returns a new instance of AttributeNode.
57 58 59 60 |
# File 'lib/red/assignment_nodes.rb', line 57 def initialize(variable_name, slot_equals, arguments) @variable_name, @expression = [variable_name, arguments.last].build_nodes @slot = (slot_equals == :[]= ? arguments[1] : slot_equals.to_s.gsub(/=/,'').to_sym).build_node end |
Instance Method Details
#compile_internals(options = {}) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/red/assignment_nodes.rb', line 66 def compile_internals( = {}) variable_name, slot = [@variable_name, @slot].compile_nodes(:quotes => '') expression = @expression.compile_node(:as_argument => true) receiver = self.compile_receiver(variable_name, slot) return [receiver, expression] end |
#compile_node(options = {}) ⇒ Object
62 63 64 |
# File 'lib/red/assignment_nodes.rb', line 62 def compile_node( = {}) return "%s = %s" % compile_internals end |
#compile_receiver(variable_name, slot) ⇒ Object
73 74 75 |
# File 'lib/red/assignment_nodes.rb', line 73 def compile_receiver(variable_name, slot) return ([:symbol, :string].include?((@slot.data_type rescue :node)) ? "%s.%s" : "%s[%s]") % [variable_name, slot] end |