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

Constructor Details

#initialize(value:, location:) ⇒ RationalLiteral

Returns a new instance of RationalLiteral.



8904
8905
8906
8907
8908
# File 'lib/syntax_tree/node.rb', line 8904

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8902
8903
8904
# File 'lib/syntax_tree/node.rb', line 8902

def comments
  @comments
end

#valueObject (readonly)

String

the rational number literal



8899
8900
8901
# File 'lib/syntax_tree/node.rb', line 8899

def value
  @value
end

Instance Method Details

#===(other) ⇒ Object



8939
8940
8941
# File 'lib/syntax_tree/node.rb', line 8939

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

#accept(visitor) ⇒ Object



8910
8911
8912
# File 'lib/syntax_tree/node.rb', line 8910

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

#child_nodesObject Also known as: deconstruct



8914
8915
8916
# File 'lib/syntax_tree/node.rb', line 8914

def child_nodes
  []
end

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



8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
# File 'lib/syntax_tree/node.rb', line 8918

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



8931
8932
8933
# File 'lib/syntax_tree/node.rb', line 8931

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

#format(q) ⇒ Object



8935
8936
8937
# File 'lib/syntax_tree/node.rb', line 8935

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