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.



12269
12270
12271
12272
12273
# File 'lib/syntax_tree.rb', line 12269

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



12267
12268
12269
# File 'lib/syntax_tree.rb', line 12267

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



12264
12265
12266
# File 'lib/syntax_tree.rb', line 12264

def location
  @location
end

#symbolsObject (readonly)

Array[ DynaSymbol | SymbolLiteral ]

the symbols to undefine



12261
12262
12263
# File 'lib/syntax_tree.rb', line 12261

def symbols
  @symbols
end

Instance Method Details

#child_nodesObject



12275
12276
12277
# File 'lib/syntax_tree.rb', line 12275

def child_nodes
  symbols
end

#format(q) ⇒ Object



12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
# File 'lib/syntax_tree.rb', line 12279

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



12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
# File 'lib/syntax_tree.rb', line 12291

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



12302
12303
12304
12305
12306
# File 'lib/syntax_tree.rb', line 12302

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