Class: SyntaxTree::Undef
Overview
Undef represents the use of the undef
keyword.
undef method
Defined Under Namespace
Classes: UndefArgumentFormatter
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#symbols ⇒ Object
readonly
- Array[ DynaSymbol | SymbolLiteral ]
-
the symbols to undefine.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(symbols:, location:, comments: []) ⇒ Undef
constructor
A new instance of Undef.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(symbols:, location:, comments: []) ⇒ Undef
Returns a new instance of Undef.
10535 10536 10537 10538 10539 |
# File 'lib/syntax_tree/node.rb', line 10535 def initialize(symbols:, location:, comments: []) @symbols = symbols @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
10533 10534 10535 |
# File 'lib/syntax_tree/node.rb', line 10533 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
10530 10531 10532 |
# File 'lib/syntax_tree/node.rb', line 10530 def location @location end |
#symbols ⇒ Object (readonly)
- Array[ DynaSymbol | SymbolLiteral ]
-
the symbols to undefine
10527 10528 10529 |
# File 'lib/syntax_tree/node.rb', line 10527 def symbols @symbols end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10541 10542 10543 |
# File 'lib/syntax_tree/node.rb', line 10541 def child_nodes symbols end |
#deconstruct_keys(keys) ⇒ Object
10547 10548 10549 |
# File 'lib/syntax_tree/node.rb', line 10547 def deconstruct_keys(keys) { symbols: symbols, location: location, comments: comments } end |
#format(q) ⇒ Object
10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 |
# File 'lib/syntax_tree/node.rb', line 10551 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
10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 |
# File 'lib/syntax_tree/node.rb', line 10563 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
10574 10575 10576 10577 10578 |
# File 'lib/syntax_tree/node.rb', line 10574 def to_json(*opts) { type: :undef, syms: symbols, loc: location, cmts: comments }.to_json( *opts ) end |