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



11685
11686
11687
11688
11689
# File 'lib/syntax_tree.rb', line 11685

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



11683
11684
11685
# File 'lib/syntax_tree.rb', line 11683

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



11680
11681
11682
# File 'lib/syntax_tree.rb', line 11680

def location
  @location
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



11677
11678
11679
# File 'lib/syntax_tree.rb', line 11677

def symbols
  @symbols
end

Instance Method Details

#child_nodesObject



11691
11692
11693
# File 'lib/syntax_tree.rb', line 11691

def child_nodes
  symbols
end

#format(q) ⇒ Object



11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
# File 'lib/syntax_tree.rb', line 11695

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



11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
# File 'lib/syntax_tree.rb', line 11707

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



11718
11719
11720
11721
11722
# File 'lib/syntax_tree.rb', line 11718

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