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:) ⇒ Undef

Returns a new instance of Undef.



11079
11080
11081
11082
11083
# File 'lib/syntax_tree/node.rb', line 11079

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



11077
11078
11079
# File 'lib/syntax_tree/node.rb', line 11077

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



11074
11075
11076
# File 'lib/syntax_tree/node.rb', line 11074

def symbols
  @symbols
end

Instance Method Details

#===(other) ⇒ Object



11122
11123
11124
# File 'lib/syntax_tree/node.rb', line 11122

def ===(other)
  other.is_a?(Undef) && ArrayMatch.call(symbols, other.symbols)
end

#accept(visitor) ⇒ Object



11085
11086
11087
# File 'lib/syntax_tree/node.rb', line 11085

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

#child_nodesObject Also known as: deconstruct



11089
11090
11091
# File 'lib/syntax_tree/node.rb', line 11089

def child_nodes
  symbols
end

#copy(symbols: nil, location: nil) ⇒ Object



11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
# File 'lib/syntax_tree/node.rb', line 11093

def copy(symbols: nil, location: nil)
  node =
    Undef.new(
      symbols: symbols || self.symbols,
      location: location || self.location
    )

  node.comments.concat(comments.map(&:copy))
  node
end

#deconstruct_keys(_keys) ⇒ Object



11106
11107
11108
# File 'lib/syntax_tree/node.rb', line 11106

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

#format(q) ⇒ Object



11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
# File 'lib/syntax_tree/node.rb', line 11110

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