123456789_123456789_123456789_123456789_123456789_

Class: Prism::DesugarOrWriteDefinedNode

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/prism/desugar_compiler.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

  • #compile

    Desugar x ||= y to defined?(x) ? x : x = y.

Constructor Details

.new(node, source, read_class, write_class, *arguments) ⇒ DesugarOrWriteDefinedNode

[ GitHub ]

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

def initialize(node, source, read_class, write_class, *arguments)
  @node = node
  @source = 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 28

attr_reader :node, :source, :read_class, :write_class, :arguments

#node (readonly)

[ GitHub ]

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

attr_reader :node, :source, :read_class, :write_class, :arguments

#read_class (readonly)

[ GitHub ]

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

attr_reader :node, :source, :read_class, :write_class, :arguments

#source (readonly)

[ GitHub ]

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

attr_reader :node, :source, :read_class, :write_class, :arguments

#write_class (readonly)

[ GitHub ]

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

attr_reader :node, :source, :read_class, :write_class, :arguments

Instance Method Details

#compile

Desugar x ||= y to defined?(x) ? x : x = y

[ GitHub ]

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

def compile
  IfNode.new(
    source,
    node.operator_loc,
    DefinedNode.new(source, nil, read_class.new(source, *arguments, node.name_loc), nil, node.operator_loc, node.name_loc),
    node.operator_loc,
    StatementsNode.new(source, [read_class.new(source, *arguments, node.name_loc)], node.location),
    ElseNode.new(
      source,
      node.operator_loc,
      StatementsNode.new(
        source,
        [write_class.new(source, *arguments, node.name_loc, node.value, node.operator_loc, node.location)],
        node.location
      ),
      node.operator_loc,
      node.location
    ),
    node.operator_loc,
    node.location
  )
end