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.
-
#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 }.
-
#each_child_node {|numeric| ... } ⇒ Object
def each_child_node: () { (Prism::node) -> void } -> void | () -> Enumerator.
-
#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.
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
#numeric ⇒ Object (readonly)
attr_reader numeric: FloatNode | IntegerNode | RationalNode
9358 9359 9360 |
# File 'lib/prism/node.rb', line 9358 def numeric @numeric end |
Class Method Details
.type ⇒ Object
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_nodes ⇒ Object Also known as: deconstruct
def child_nodes: () -> Array
9323 9324 9325 |
# File 'lib/prism/node.rb', line 9323 def child_nodes [numeric] end |
#comment_targets ⇒ Object
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_nodes ⇒ Object
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
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 |
#inspect ⇒ Object
def inspect -> String
9361 9362 9363 |
# File 'lib/prism/node.rb', line 9361 def inspect InspectVisitor.compose(self) end |
#type ⇒ Object
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 |
#value ⇒ Object
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 |