Class: SyntaxTree::Undef

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

Overview

Undef represents the use of the undef keyword.

undef method

Defined Under Namespace

Classes: UndefArgumentFormatter

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(symbols:, location:, comments: []) ⇒ Undef

Returns a new instance of Undef.



8852
8853
8854
8855
8856
# File 'lib/syntax_tree/node.rb', line 8852

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8850
8851
8852
# File 'lib/syntax_tree/node.rb', line 8850

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



8847
8848
8849
# File 'lib/syntax_tree/node.rb', line 8847

def symbols
  @symbols
end

Instance Method Details

#accept(visitor) ⇒ Object



8858
8859
8860
# File 'lib/syntax_tree/node.rb', line 8858

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

#child_nodesObject Also known as: deconstruct



8862
8863
8864
# File 'lib/syntax_tree/node.rb', line 8862

def child_nodes
  symbols
end

#deconstruct_keys(keys) ⇒ Object



8868
8869
8870
# File 'lib/syntax_tree/node.rb', line 8868

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

#format(q) ⇒ Object



8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
# File 'lib/syntax_tree/node.rb', line 8872

def format(q)
  keyword = "undef "
  formatters = symbols.map { |symbol| UndefArgumentFormatter.new(symbol) }

  q.group do
    q.text(keyword)
    q.nest(keyword.length) do
      q.seplist(formatters) { |formatter| q.format(formatter) }
    end
  end
end