Class: YARP::ImaginaryNode

Inherits:
YARPNode
  • Object
show all
Defined in:
lib/yarp/node.rb,
lib/yarp.rb,
ext/yarp/api_node.c

Overview

Represents an imaginary number literal.

1.0i
^^^^

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numeric, location) ⇒ ImaginaryNode

def initialize: (numeric: Node, location: Location) -> void



5200
5201
5202
5203
# File 'lib/yarp/node.rb', line 5200

def initialize(numeric, location)
  @numeric = numeric
  @location = location
end

Instance Attribute Details

#numericObject (readonly)

attr_reader numeric: Node



5197
5198
5199
# File 'lib/yarp/node.rb', line 5197

def numeric
  @numeric
end

Instance Method Details

#accept(visitor) ⇒ Object

def accept: (visitor: Visitor) -> void



5206
5207
5208
# File 'lib/yarp/node.rb', line 5206

def accept(visitor)
  visitor.visit_imaginary_node(self)
end

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array[nil | Node]



5211
5212
5213
# File 'lib/yarp/node.rb', line 5211

def child_nodes
  [numeric]
end

#comment_targetsObject

def comment_targets: () -> Array[Node | Location]



5216
5217
5218
# File 'lib/yarp/node.rb', line 5216

def comment_targets
  [numeric]
end

#copy(**params) ⇒ Object

def copy: (**params) -> ImaginaryNode



5221
5222
5223
5224
5225
5226
# File 'lib/yarp/node.rb', line 5221

def copy(**params)
  ImaginaryNode.new(
    params.fetch(:numeric) { numeric },
    params.fetch(:location) { location },
  )
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (keys: Array) -> Hash[Symbol, nil | Node | Array | String | Token | Array | Location]



5232
5233
5234
# File 'lib/yarp/node.rb', line 5232

def deconstruct_keys(keys)
  { numeric: numeric, location: location }
end

#inspect(inspector = NodeInspector.new) ⇒ Object



5236
5237
5238
5239
5240
5241
# File 'lib/yarp/node.rb', line 5236

def inspect(inspector = NodeInspector.new)
  inspector << inspector.header(self)
  inspector << "└── numeric:\n"
  inspector << inspector.child_node(numeric, "    ")
  inspector.to_str
end

#valueObject



399
400
401
# File 'lib/yarp.rb', line 399

def value
  Complex(0, numeric.value)
end