Class: Prism::ImaginaryNode

Inherits:
PrismNode
  • Object
show all
Defined in:
lib/prism/node.rb,
lib/prism/node_ext.rb,
ext/prism/api_node.c

Overview

Represents an imaginary number literal.

1.0i
^^^^

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, node_id, location, flags, numeric) ⇒ ImaginaryNode

Initialize a new ImaginaryNode node.



9309
9310
9311
9312
9313
9314
9315
# File 'lib/prism/node.rb', line 9309

def initialize(source, node_id, location, flags, numeric)
  @source = source
  @node_id = node_id
  @location = location
  @flags = flags
  @numeric = numeric
end

Instance Attribute Details

#numericObject (readonly)

attr_reader numeric: FloatNode | IntegerNode | RationalNode



9358
9359
9360
# File 'lib/prism/node.rb', line 9358

def numeric
  @numeric
end

Class Method Details

.typeObject

Return a symbol representation of this node type. See Node::type.



9371
9372
9373
# File 'lib/prism/node.rb', line 9371

def self.type
  :imaginary_node
end

Instance Method Details

#===(other) ⇒ Object

Implements case-equality for the node. This is effectively == but without comparing the value of locations. Locations are checked only for presence.



9377
9378
9379
9380
# File 'lib/prism/node.rb', line 9377

def ===(other)
  other.is_a?(ImaginaryNode) &&
    (numeric === other.numeric)
end

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



9318
9319
9320
# File 'lib/prism/node.rb', line 9318

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

#child_nodesObject Also known as: deconstruct

def child_nodes: () -> Array



9323
9324
9325
# File 'lib/prism/node.rb', line 9323

def child_nodes
  [numeric]
end

#comment_targetsObject

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



9340
9341
9342
# File 'lib/prism/node.rb', line 9340

def comment_targets
  [numeric] #: Array[Prism::node | Location]
end

#compact_child_nodesObject

def compact_child_nodes: () -> Array



9335
9336
9337
# File 'lib/prism/node.rb', line 9335

def compact_child_nodes
  [numeric]
end

#copy(node_id: self.node_id, location: self.location, flags: self.flags, numeric: self.numeric) ⇒ Object

def copy: (?node_id: Integer, ?location: Location, ?flags: Integer, ?numeric: FloatNode | IntegerNode | RationalNode) -> ImaginaryNode



9345
9346
9347
# File 'lib/prism/node.rb', line 9345

def copy(node_id: self.node_id, location: self.location, flags: self.flags, numeric: self.numeric)
  ImaginaryNode.new(source, node_id, location, flags, numeric)
end

#deconstruct_keys(keys) ⇒ Object

def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, numeric: FloatNode | IntegerNode | RationalNode }



9353
9354
9355
# File 'lib/prism/node.rb', line 9353

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

#each_child_node {|numeric| ... } ⇒ Object

def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator

Yields:



9328
9329
9330
9331
9332
# File 'lib/prism/node.rb', line 9328

def each_child_node
  return to_enum(:each_child_node) unless block_given?

  yield numeric
end

#inspectObject

def inspect -> String



9361
9362
9363
# File 'lib/prism/node.rb', line 9361

def inspect
  InspectVisitor.compose(self)
end

#typeObject

Return a symbol representation of this node type. See ‘Node#type`.



9366
9367
9368
# File 'lib/prism/node.rb', line 9366

def type
  :imaginary_node
end

#valueObject

Returns the value of the node as a Ruby Complex.



110
111
112
# File 'lib/prism/node_ext.rb', line 110

def value
  Complex(0, numeric.value)
end