Class: SyntaxTree::Word

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

Overview

Word represents an element within a special array literal that accepts interpolation.

%W[a#{b}c xyz]

In the example above, there would be two Word nodes within a parent Words node.

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(parts:, location:, comments: []) ⇒ Word

Returns a new instance of Word.



9066
9067
9068
9069
9070
# File 'lib/syntax_tree/node.rb', line 9066

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



9064
9065
9066
# File 'lib/syntax_tree/node.rb', line 9064

def comments
  @comments
end

#partsObject (readonly)

Array[ StringEmbExpr | StringDVar | TStringContent ]

the parts of the

word



9061
9062
9063
# File 'lib/syntax_tree/node.rb', line 9061

def parts
  @parts
end

Instance Method Details

#accept(visitor) ⇒ Object



9076
9077
9078
# File 'lib/syntax_tree/node.rb', line 9076

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

#child_nodesObject Also known as: deconstruct



9080
9081
9082
# File 'lib/syntax_tree/node.rb', line 9080

def child_nodes
  parts
end

#deconstruct_keys(keys) ⇒ Object



9086
9087
9088
# File 'lib/syntax_tree/node.rb', line 9086

def deconstruct_keys(keys)
  { parts: parts, location: location, comments: comments }
end

#format(q) ⇒ Object



9090
9091
9092
# File 'lib/syntax_tree/node.rb', line 9090

def format(q)
  q.format_each(parts)
end

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


9072
9073
9074
# File 'lib/syntax_tree/node.rb', line 9072

def match?(pattern)
  parts.any? { |part| part.is_a?(TStringContent) && part.match?(pattern) }
end