Class: SyntaxTree::Undef

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.rb

Overview

Undef represents the use of the undef keyword.

undef method

Defined Under Namespace

Classes: UndefArgumentFormatter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Undef.



12189
12190
12191
12192
12193
# File 'lib/syntax_tree.rb', line 12189

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



12187
12188
12189
# File 'lib/syntax_tree.rb', line 12187

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12184
12185
12186
# File 'lib/syntax_tree.rb', line 12184

def location
  @location
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



12181
12182
12183
# File 'lib/syntax_tree.rb', line 12181

def symbols
  @symbols
end

Instance Method Details

#child_nodesObject



12195
12196
12197
# File 'lib/syntax_tree.rb', line 12195

def child_nodes
  symbols
end

#format(q) ⇒ Object



12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
# File 'lib/syntax_tree.rb', line 12199

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



12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
# File 'lib/syntax_tree.rb', line 12211

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



12222
12223
12224
12225
12226
# File 'lib/syntax_tree.rb', line 12222

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