Class: Prism::ImaginaryNode
- Inherits:
-
PrismNode
- Object
- PrismNode
- Prism::ImaginaryNode
- 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
-
#numeric ⇒ Object
readonly
attr_reader numeric: FloatNode | IntegerNode | RationalNode.
Class Method Summary collapse
-
.type ⇒ Object
Return a symbol representation of this node type.
Instance Method Summary collapse
-
#===(other) ⇒ Object
Implements case-equality for the node.
-
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void.
-
#child_nodes ⇒ Object
(also: #deconstruct)
def child_nodes: () -> Array[nil | Node].
-
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location].
-
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array.
-
#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.
-
#deconstruct_keys(keys) ⇒ Object
def deconstruct_keys: (Array keys) -> { node_id: Integer, location: Location, numeric: FloatNode | IntegerNode | RationalNode }.
-
#initialize(source, node_id, location, flags, numeric) ⇒ ImaginaryNode
constructor
Initialize a new ImaginaryNode node.
-
#inspect ⇒ Object
def inspect -> String.
-
#type ⇒ Object
Return a symbol representation of this node type.
-
#value ⇒ Object
Returns the value of the node as a Ruby Complex.
Constructor Details
#initialize(source, node_id, location, flags, numeric) ⇒ ImaginaryNode
Initialize a new ImaginaryNode node.
7675 7676 7677 7678 7679 7680 7681 |
# File 'lib/prism/node.rb', line 7675 def initialize(source, node_id, location, flags, numeric) @source = source @node_id = node_id @location = location @flags = flags @numeric = numeric end |
Instance Attribute Details
#numeric ⇒ Object (readonly)
attr_reader numeric: FloatNode | IntegerNode | RationalNode
7717 7718 7719 |
# File 'lib/prism/node.rb', line 7717 def numeric @numeric end |
Class Method Details
.type ⇒ Object
Return a symbol representation of this node type. See ‘Node::type`.
7730 7731 7732 |
# File 'lib/prism/node.rb', line 7730 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.
7736 7737 7738 7739 |
# File 'lib/prism/node.rb', line 7736 def ===(other) other.is_a?(ImaginaryNode) && (numeric === other.numeric) end |
#accept(visitor) ⇒ Object
def accept: (Visitor visitor) -> void
7684 7685 7686 |
# File 'lib/prism/node.rb', line 7684 def accept(visitor) visitor.visit_imaginary_node(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array[nil | Node]
7689 7690 7691 |
# File 'lib/prism/node.rb', line 7689 def child_nodes [numeric] end |
#comment_targets ⇒ Object
def comment_targets: () -> Array[Node | Location]
7699 7700 7701 |
# File 'lib/prism/node.rb', line 7699 def comment_targets [numeric] #: Array[Prism::node | Location] end |
#compact_child_nodes ⇒ Object
def compact_child_nodes: () -> Array
7694 7695 7696 |
# File 'lib/prism/node.rb', line 7694 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
7704 7705 7706 |
# File 'lib/prism/node.rb', line 7704 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 }
7712 7713 7714 |
# File 'lib/prism/node.rb', line 7712 def deconstruct_keys(keys) { node_id: node_id, location: location, numeric: numeric } end |
#inspect ⇒ Object
def inspect -> String
7720 7721 7722 |
# File 'lib/prism/node.rb', line 7720 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
Return a symbol representation of this node type. See ‘Node#type`.
7725 7726 7727 |
# File 'lib/prism/node.rb', line 7725 def type :imaginary_node end |
#value ⇒ Object
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 |