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.



12401
12402
12403
12404
12405
# File 'lib/syntax_tree.rb', line 12401

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



12399
12400
12401
# File 'lib/syntax_tree.rb', line 12399

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12396
12397
12398
# File 'lib/syntax_tree.rb', line 12396

def location
  @location
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



12393
12394
12395
# File 'lib/syntax_tree.rb', line 12393

def symbols
  @symbols
end

Instance Method Details

#child_nodesObject



12407
12408
12409
# File 'lib/syntax_tree.rb', line 12407

def child_nodes
  symbols
end

#format(q) ⇒ Object



12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
# File 'lib/syntax_tree.rb', line 12411

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



12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
# File 'lib/syntax_tree.rb', line 12423

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



12434
12435
12436
12437
12438
# File 'lib/syntax_tree.rb', line 12434

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