Class: Prism::DesugarOrWriteDefinedNode
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
- #arguments readonly
- #default_source readonly
- #node readonly
- #read_class readonly
- #write_class readonly
Instance Method Summary
-
#compile
Desugar
x ||= y
todefined?(x) ? x : x = y
.
Constructor Details
.new(node, default_source, read_class, write_class, **arguments) ⇒ DesugarOrWriteDefinedNode
# File 'lib/prism/desugar_compiler.rb', line 40
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 38
attr_reader :node, :default_source, :read_class, :write_class, :arguments
#default_source (readonly)
[ GitHub ]# File 'lib/prism/desugar_compiler.rb', line 38
attr_reader :node, :default_source, :read_class, :write_class, :arguments
#node (readonly)
[ GitHub ]# File 'lib/prism/desugar_compiler.rb', line 38
attr_reader :node, :default_source, :read_class, :write_class, :arguments
#read_class (readonly)
[ GitHub ]# File 'lib/prism/desugar_compiler.rb', line 38
attr_reader :node, :default_source, :read_class, :write_class, :arguments
#write_class (readonly)
[ GitHub ]# File 'lib/prism/desugar_compiler.rb', line 38
attr_reader :node, :default_source, :read_class, :write_class, :arguments
Instance Method Details
#compile
Desugar x ||= y
to defined?(x) ? x : x = y
# File 'lib/prism/desugar_compiler.rb', line 49
def compile if_node( location: node.location, if_keyword_loc: node.operator_loc, predicate: defined_node( location: node.name_loc, value: public_send(read_class, location: node.name_loc, **arguments), keyword_loc: node.operator_loc ), then_keyword_loc: node.operator_loc, statements: statements_node( location: node.location, body: [public_send(read_class, location: node.name_loc, **arguments)] ), subsequent: else_node( location: node.location, else_keyword_loc: node.operator_loc, statements: statements_node( location: node.location, body: [ public_send( write_class, location: node.location, **arguments, name_loc: node.name_loc, value: node.value, operator_loc: node.operator_loc ) ] ), end_keyword_loc: node.operator_loc ), end_keyword_loc: node.operator_loc ) end