Class: SyntaxTree::RationalLiteral

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

Overview

RationalLiteral represents the use of a rational number literal.

1r

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:) ⇒ RationalLiteral

Returns a new instance of RationalLiteral.



8791
8792
8793
8794
8795
# File 'lib/syntax_tree/node.rb', line 8791

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8789
8790
8791
# File 'lib/syntax_tree/node.rb', line 8789

def comments
  @comments
end

#valueObject (readonly)

String

the rational number literal



8786
8787
8788
# File 'lib/syntax_tree/node.rb', line 8786

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



8826
8827
8828
# File 'lib/syntax_tree/node.rb', line 8826

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

#accept(visitor) ⇒ Object



8797
8798
8799
# File 'lib/syntax_tree/node.rb', line 8797

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

#child_nodesObject Also known as: deconstruct



8801
8802
8803
# File 'lib/syntax_tree/node.rb', line 8801

def child_nodes
  []
end

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



8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
# File 'lib/syntax_tree/node.rb', line 8805

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

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

#deconstruct_keys(_keys) ⇒ Object



8818
8819
8820
# File 'lib/syntax_tree/node.rb', line 8818

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

#format(q) ⇒ Object



8822
8823
8824
# File 'lib/syntax_tree/node.rb', line 8822

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