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.



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

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



9083
9084
9085
# File 'lib/syntax_tree/node.rb', line 9083

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



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

def symbols
  @symbols
end

Instance Method Details

#accept(visitor) ⇒ Object



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

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

#child_nodesObject Also known as: deconstruct



9095
9096
9097
# File 'lib/syntax_tree/node.rb', line 9095

def child_nodes
  symbols
end

#deconstruct_keys(_keys) ⇒ Object



9101
9102
9103
# File 'lib/syntax_tree/node.rb', line 9101

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

#format(q) ⇒ Object



9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
# File 'lib/syntax_tree/node.rb', line 9105

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