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.



6560
6561
6562
6563
6564
# File 'lib/syntax_tree/node.rb', line 6560

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



6558
6559
6560
# File 'lib/syntax_tree/node.rb', line 6558

def comments
  @comments
end

#valueObject (readonly)

String

the value of the imaginary number literal



6555
6556
6557
# File 'lib/syntax_tree/node.rb', line 6555

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



6595
6596
6597
# File 'lib/syntax_tree/node.rb', line 6595

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

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



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

def child_nodes
  []
end

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



6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
# File 'lib/syntax_tree/node.rb', line 6574

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



6587
6588
6589
# File 'lib/syntax_tree/node.rb', line 6587

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

#format(q) ⇒ Object



6591
6592
6593
# File 'lib/syntax_tree/node.rb', line 6591

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