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.



7638
7639
7640
7641
7642
7643
7644
# File 'lib/prism/node.rb', line 7638

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



7680
7681
7682
# File 'lib/prism/node.rb', line 7680

def numeric
  @numeric
end

Class Method Details

.typeObject

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



7693
7694
7695
# File 'lib/prism/node.rb', line 7693

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.



7699
7700
7701
7702
# File 'lib/prism/node.rb', line 7699

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

#accept(visitor) ⇒ Object

def accept: (Visitor visitor) -> void



7647
7648
7649
# File 'lib/prism/node.rb', line 7647

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

#child_nodesObject Also known as: deconstruct

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



7652
7653
7654
# File 'lib/prism/node.rb', line 7652

def child_nodes
  [numeric]
end

#comment_targetsObject

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



7662
7663
7664
# File 'lib/prism/node.rb', line 7662

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

#compact_child_nodesObject

def compact_child_nodes: () -> Array



7657
7658
7659
# File 'lib/prism/node.rb', line 7657

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



7667
7668
7669
# File 'lib/prism/node.rb', line 7667

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 }



7675
7676
7677
# File 'lib/prism/node.rb', line 7675

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

#inspectObject

def inspect -> String



7683
7684
7685
# File 'lib/prism/node.rb', line 7683

def inspect
  InspectVisitor.compose(self)
end

#typeObject

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



7688
7689
7690
# File 'lib/prism/node.rb', line 7688

def type
  :imaginary_node
end

#valueObject

Returns the value of the node as a Ruby Complex.



107
108
109
# File 'lib/prism/node_ext.rb', line 107

def value
  Complex(0, numeric.value)
end