Class: SyntaxTree::Imaginary

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

Imaginary represents an imaginary number literal.

1i

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid

Constructor Details

#initialize(value:, location:) ⇒ Imaginary

Returns a new instance of Imaginary.



6687
6688
6689
6690
6691
# File 'lib/syntax_tree/node.rb', line 6687

def initialize(value:, location:)
  @value = value
  @location = location
  @comments = []
end

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6685
6686
6687
# File 'lib/syntax_tree/node.rb', line 6685

def comments
  @comments
end

#valueObject (readonly)

String

the value of the imaginary number literal



6682
6683
6684
# File 'lib/syntax_tree/node.rb', line 6682

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6722
6723
6724
# File 'lib/syntax_tree/node.rb', line 6722

def ===(other)
  other.is_a?(Imaginary) && value === other.value
end

#accept(visitor) ⇒ Object



6693
6694
6695
# File 'lib/syntax_tree/node.rb', line 6693

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

#child_nodesObject Also known as: deconstruct



6697
6698
6699
# File 'lib/syntax_tree/node.rb', line 6697

def child_nodes
  []
end

#copy(value: nil, location: nil) ⇒ Object



6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
# File 'lib/syntax_tree/node.rb', line 6701

def copy(value: nil, location: nil)
  node =
    Imaginary.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



6714
6715
6716
# File 'lib/syntax_tree/node.rb', line 6714

def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end

#format(q) ⇒ Object



6718
6719
6720
# File 'lib/syntax_tree/node.rb', line 6718

def format(q)
  q.text(value)
end