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.
-
#symbols ⇒ Object
readonly
- Array[ DynaSymbol | SymbolLiteral ]
-
the symbols to undefine.
Attributes inherited from Node
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.
10121 10122 10123 10124 10125 |
# File 'lib/syntax_tree/node.rb', line 10121 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
10119 10120 10121 |
# File 'lib/syntax_tree/node.rb', line 10119 def comments @comments end |
#symbols ⇒ Object (readonly)
- Array[ DynaSymbol | SymbolLiteral ]
-
the symbols to undefine
10116 10117 10118 |
# File 'lib/syntax_tree/node.rb', line 10116 def symbols @symbols end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
10127 10128 10129 |
# File 'lib/syntax_tree/node.rb', line 10127 def child_nodes symbols end |
#deconstruct_keys(keys) ⇒ Object
10133 10134 10135 |
# File 'lib/syntax_tree/node.rb', line 10133 def deconstruct_keys(keys) { symbols: symbols, location: location, comments: comments } end |
#format(q) ⇒ Object
10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 |
# File 'lib/syntax_tree/node.rb', line 10137 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
10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 |
# File 'lib/syntax_tree/node.rb', line 10149 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
10160 10161 10162 10163 10164 |
# File 'lib/syntax_tree/node.rb', line 10160 def to_json(*opts) { type: :undef, syms: symbols, loc: location, cmts: comments }.to_json( *opts ) end |