class SyntaxTree::Int
Int
represents an integer number literal.
1
Attributes
value[R]
- String
-
the value of the integer
Public Class Methods
new(value:, location:)
click to toggle source
# File lib/syntax_tree/node.rb, line 6829 def initialize(value:, location:) @value = value @location = location @comments = [] end
Public Instance Methods
===(other)
click to toggle source
# File lib/syntax_tree/node.rb, line 6869 def ===(other) other.is_a?(Int) && value === other.value end
accept(visitor)
click to toggle source
# File lib/syntax_tree/node.rb, line 6835 def accept(visitor) visitor.visit_int(self) end
child_nodes()
click to toggle source
# File lib/syntax_tree/node.rb, line 6839 def child_nodes [] end
Also aliased as: deconstruct
copy(value: nil, location: nil)
click to toggle source
# File lib/syntax_tree/node.rb, line 6843 def copy(value: nil, location: nil) node = Int.new(value: value || self.value, location: location || self.location) node.comments.concat(comments.map(&:copy)) node end
deconstruct_keys(_keys)
click to toggle source
# File lib/syntax_tree/node.rb, line 6853 def deconstruct_keys(_keys) { value: value, location: location, comments: comments } end
format(q)
click to toggle source
# File lib/syntax_tree/node.rb, line 6857 def format(q) if !value.start_with?(/\+?0/) && value.length >= 5 && !value.include?("_") # If it's a plain integer and it doesn't have any underscores separating # the values, then we're going to insert them every 3 characters # starting from the right. index = (value.length + 2) % 3 q.text(" #{value}"[index..].scan(/.../).join("_").strip) else q.text(value) end end