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

Constructor Details

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

Returns a new instance of Undef.



10121
10122
10123
10124
10125
# File 'lib/syntax_tree/node.rb', line 10121

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



10119
10120
10121
# File 'lib/syntax_tree/node.rb', line 10119

def comments
  @comments
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



10116
10117
10118
# File 'lib/syntax_tree/node.rb', line 10116

def symbols
  @symbols
end

Instance Method Details

#child_nodesObject Also known as: deconstruct



10127
10128
10129
# File 'lib/syntax_tree/node.rb', line 10127

def child_nodes
  symbols
end

#deconstruct_keys(keys) ⇒ Object



10133
10134
10135
# File 'lib/syntax_tree/node.rb', line 10133

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

#format(q) ⇒ Object



10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
# File 'lib/syntax_tree/node.rb', line 10137

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

#pretty_print(q) ⇒ Object



10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
# File 'lib/syntax_tree/node.rb', line 10149

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("undef")

    q.breakable
    q.group(2, "(", ")") { q.seplist(symbols) { |symbol| q.pp(symbol) } }

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



10160
10161
10162
10163
10164
# File 'lib/syntax_tree/node.rb', line 10160

def to_json(*opts)
  { type: :undef, syms: symbols, loc: location, cmts: comments }.to_json(
    *opts
  )
end