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
- #===(other) ⇒ Object
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #copy(symbols: nil, location: nil) ⇒ Object
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(symbols:, location:) ⇒ Undef
constructor
A new instance of Undef.
Methods inherited from Node
#construct_keys, #end_char, #pretty_print, #start_char, #to_json, #to_mermaid
Constructor Details
#initialize(symbols:, location:) ⇒ Undef
Returns a new instance of Undef.
11207 11208 11209 11210 11211 |
# File 'lib/syntax_tree/node.rb', line 11207 def initialize(symbols:, location:) @symbols = symbols @location = location @comments = [] end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
11205 11206 11207 |
# File 'lib/syntax_tree/node.rb', line 11205 def comments @comments end |
#symbols ⇒ Object (readonly)
- Array[ DynaSymbol | SymbolLiteral ]
-
the symbols to undefine
11202 11203 11204 |
# File 'lib/syntax_tree/node.rb', line 11202 def symbols @symbols end |
Instance Method Details
#===(other) ⇒ Object
11250 11251 11252 |
# File 'lib/syntax_tree/node.rb', line 11250 def ===(other) other.is_a?(Undef) && ArrayMatch.call(symbols, other.symbols) end |
#accept(visitor) ⇒ Object
11213 11214 11215 |
# File 'lib/syntax_tree/node.rb', line 11213 def accept(visitor) visitor.visit_undef(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
11217 11218 11219 |
# File 'lib/syntax_tree/node.rb', line 11217 def child_nodes symbols end |
#copy(symbols: nil, location: nil) ⇒ Object
11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 |
# File 'lib/syntax_tree/node.rb', line 11221 def copy(symbols: nil, location: nil) node = Undef.new( symbols: symbols || self.symbols, location: location || self.location ) node.comments.concat(comments.map(&:copy)) node end |
#deconstruct_keys(_keys) ⇒ Object
11234 11235 11236 |
# File 'lib/syntax_tree/node.rb', line 11234 def deconstruct_keys(_keys) { symbols: symbols, location: location, comments: comments } end |
#format(q) ⇒ Object
11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 |
# File 'lib/syntax_tree/node.rb', line 11238 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 |