123456789_123456789_123456789_123456789_123456789_

Class: Prism::DesugarOperatorWriteNode

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, DSL
Inherits: Object
Defined in: lib/prism/desugar_compiler.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(node, default_source, read_class, write_class, **arguments) ⇒ DesugarOperatorWriteNode

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 91

def initialize(node, default_source, read_class, write_class, **arguments)
  @node = node
  @default_source = default_source
  @read_class = read_class
  @write_class = write_class
  @arguments = arguments
end

Instance Attribute Details

#arguments (readonly)

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 89

attr_reader :node, :default_source, :read_class, :write_class, :arguments

#default_source (readonly)

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 89

attr_reader :node, :default_source, :read_class, :write_class, :arguments

#node (readonly)

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 89

attr_reader :node, :default_source, :read_class, :write_class, :arguments

#read_class (readonly)

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 89

attr_reader :node, :default_source, :read_class, :write_class, :arguments

#write_class (readonly)

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 89

attr_reader :node, :default_source, :read_class, :write_class, :arguments

Instance Method Details

#compile

Desugar x += y to x = x + y

[ GitHub ]

  
# File 'lib/prism/desugar_compiler.rb', line 100

def compile
  binary_operator_loc = node.binary_operator_loc.chop

  public_send(
    write_class,
    location: node.location,
    **arguments,
    name_loc: node.name_loc,
    value: call_node(
      location: node.location,
      receiver: public_send(
        read_class,
        location: node.name_loc,
        **arguments
      ),
      name: binary_operator_loc.slice.to_sym,
      message_loc: binary_operator_loc,
      arguments: arguments_node(
        location: node.value.location,
        arguments: [node.value]
      )
    ),
    operator_loc: node.binary_operator_loc.copy(
      start_offset: node.binary_operator_loc.end_offset - 1,
      length: 1
    )
  )
end