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

#construct_keys, #pretty_print, #to_json

Constructor Details

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

Returns a new instance of Undef.



9040
9041
9042
9043
9044
# File 'lib/syntax_tree/node.rb', line 9040

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



9038
9039
9040
# File 'lib/syntax_tree/node.rb', line 9038

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



9035
9036
9037
# File 'lib/syntax_tree/node.rb', line 9035

def symbols
  @symbols
end

Instance Method Details

#accept(visitor) ⇒ Object



9046
9047
9048
# File 'lib/syntax_tree/node.rb', line 9046

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

#child_nodesObject Also known as: deconstruct



9050
9051
9052
# File 'lib/syntax_tree/node.rb', line 9050

def child_nodes
  symbols
end

#deconstruct_keys(_keys) ⇒ Object



9056
9057
9058
# File 'lib/syntax_tree/node.rb', line 9056

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

#format(q) ⇒ Object



9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
# File 'lib/syntax_tree/node.rb', line 9060

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