123456789_123456789_123456789_123456789_123456789_

Class: Prism::ImaginaryNode

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, PrismNode
Instance Chain:
self, PrismNode
Inherits: PrismNode
  • ::Object
Defined in: lib/prism/node.rb,
ext/prism/api_node.c,
lib/prism/node_ext.rb

Overview

Represents an imaginary number literal.

1.0i
^^^^

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(source, node_id, location, flags, numeric) ⇒ ImaginaryNode

Initialize a new ImaginaryNode node.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7496

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

Class Method Details

.type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7550

def self.type
  :imaginary_node
end

Instance Attribute Details

#numeric (readonly)

attr_reader numeric: FloatNode | IntegerNode | RationalNode

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7538

attr_reader :numeric

Instance Method Details

#===(other)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7556

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

#accept(visitor)

def accept: (Visitor visitor) -> void

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7505

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

#child_nodes Also known as: #deconstruct

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7510

def child_nodes
  [numeric]
end

#comment_targets

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7520

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

#compact_child_nodes

def compact_child_nodes: () -> Array

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7515

def compact_child_nodes
  [numeric]
end

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

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7525

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

Alias for #child_nodes.

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7530

alias deconstruct child_nodes

#deconstruct_keys(keys)

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7533

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

#inspect

def inspect -> String

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7540

def inspect
  InspectVisitor.compose(self)
end

#type

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

[ GitHub ]

  
# File 'lib/prism/node.rb', line 7545

def type
  :imaginary_node
end

#value

Returns the value of the node as a Ruby Complex.

[ GitHub ]

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

def value
  Complex(0, numeric.value)
end