class SyntaxTree::CHAR

CHAR irepresents a single codepoint in the script encoding.

?a

In the example above, the CHAR node represents the string literal “a”. You can use control characters with this as well, as in ?C-a.

Attributes

comments[R]
Array[ Comment | EmbDoc ]

the comments attached to this node

value[R]
String

the value of the character literal

Public Class Methods

new(value:, location:) click to toggle source
# File lib/syntax_tree/node.rb, line 255
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 296
def ===(other)
  other.is_a?(CHAR) && value === other.value
end
accept(visitor) click to toggle source
# File lib/syntax_tree/node.rb, line 261
def accept(visitor)
  visitor.visit_CHAR(self)
end
child_nodes() click to toggle source
# File lib/syntax_tree/node.rb, line 265
def child_nodes
  []
end
Also aliased as: deconstruct
copy(value: nil, location: nil) click to toggle source
# File lib/syntax_tree/node.rb, line 269
def copy(value: nil, location: nil)
  node =
    CHAR.new(
      value: value || self.value,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end
deconstruct()
Alias for: child_nodes
deconstruct_keys(_keys) click to toggle source
# File lib/syntax_tree/node.rb, line 282
def deconstruct_keys(_keys)
  { value: value, location: location, comments: comments }
end
format(q) click to toggle source
# File lib/syntax_tree/node.rb, line 286
def format(q)
  if value.length != 2
    q.text(value)
  else
    q.text(q.quote)
    q.text(value[1] == "\"" ? "\\\"" : value[1])
    q.text(q.quote)
  end
end