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.



8963
8964
8965
8966
8967
# File 'lib/syntax_tree/node.rb', line 8963

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



8961
8962
8963
# File 'lib/syntax_tree/node.rb', line 8961

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



8958
8959
8960
# File 'lib/syntax_tree/node.rb', line 8958

def symbols
  @symbols
end

Instance Method Details

#accept(visitor) ⇒ Object



8969
8970
8971
# File 'lib/syntax_tree/node.rb', line 8969

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

#child_nodesObject Also known as: deconstruct



8973
8974
8975
# File 'lib/syntax_tree/node.rb', line 8973

def child_nodes
  symbols
end

#deconstruct_keys(_keys) ⇒ Object



8979
8980
8981
# File 'lib/syntax_tree/node.rb', line 8979

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

#format(q) ⇒ Object



8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
# File 'lib/syntax_tree/node.rb', line 8983

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