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, #pretty_print, #to_json

Constructor Details

#initialize(value:, location:) ⇒ Imaginary

Returns a new instance of Imaginary.



6572
6573
6574
6575
6576
# File 'lib/syntax_tree/node.rb', line 6572

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6570
6571
6572
# File 'lib/syntax_tree/node.rb', line 6570

def comments
  @comments
end

#valueObject (readonly)

String

the value of the imaginary number literal



6567
6568
6569
# File 'lib/syntax_tree/node.rb', line 6567

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6607
6608
6609
# File 'lib/syntax_tree/node.rb', line 6607

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

#accept(visitor) ⇒ Object



6578
6579
6580
# File 'lib/syntax_tree/node.rb', line 6578

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

#child_nodesObject Also known as: deconstruct



6582
6583
6584
# File 'lib/syntax_tree/node.rb', line 6582

def child_nodes
  []
end

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



6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
# File 'lib/syntax_tree/node.rb', line 6586

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



6599
6600
6601
# File 'lib/syntax_tree/node.rb', line 6599

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

#format(q) ⇒ Object



6603
6604
6605
# File 'lib/syntax_tree/node.rb', line 6603

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