Class: SyntaxTree::HashLiteral
Overview
HashLiteral represents a hash literal.
{ key => value }
Defined Under Namespace
Classes: EmptyWithCommentsFormatter
Instance Attribute Summary collapse
-
#assocs ⇒ Object
readonly
- Array[ AssocNew | AssocSplat ]
-
the optional contents of the hash.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#lbrace ⇒ Object
readonly
- LBrace
-
the left brace that opens this hash.
Attributes inherited from Node
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(_keys) ⇒ Object
- #format(q) ⇒ Object
- #format_key(q, key) ⇒ Object
-
#initialize(lbrace:, assocs:, location:, comments: []) ⇒ HashLiteral
constructor
A new instance of HashLiteral.
Methods inherited from Node
#construct_keys, #pretty_print, #to_json
Constructor Details
#initialize(lbrace:, assocs:, location:, comments: []) ⇒ HashLiteral
Returns a new instance of HashLiteral.
4699 4700 4701 4702 4703 4704 |
# File 'lib/syntax_tree/node.rb', line 4699 def initialize(lbrace:, assocs:, location:, comments: []) @lbrace = lbrace @assocs = assocs @location = location @comments = comments end |
Instance Attribute Details
#assocs ⇒ Object (readonly)
- Array[ AssocNew | AssocSplat ]
-
the optional contents of the hash
4694 4695 4696 |
# File 'lib/syntax_tree/node.rb', line 4694 def assocs @assocs end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
4697 4698 4699 |
# File 'lib/syntax_tree/node.rb', line 4697 def comments @comments end |
#lbrace ⇒ Object (readonly)
- LBrace
-
the left brace that opens this hash
4691 4692 4693 |
# File 'lib/syntax_tree/node.rb', line 4691 def lbrace @lbrace end |
Instance Method Details
#accept(visitor) ⇒ Object
4706 4707 4708 |
# File 'lib/syntax_tree/node.rb', line 4706 def accept(visitor) visitor.visit_hash(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4710 4711 4712 |
# File 'lib/syntax_tree/node.rb', line 4710 def child_nodes [lbrace] + assocs end |
#deconstruct_keys(_keys) ⇒ Object
4716 4717 4718 |
# File 'lib/syntax_tree/node.rb', line 4716 def deconstruct_keys(_keys) { lbrace: lbrace, assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
4720 4721 4722 4723 4724 4725 4726 |
# File 'lib/syntax_tree/node.rb', line 4720 def format(q) if q.parent.is_a?(Assoc) format_contents(q) else q.group { format_contents(q) } end end |
#format_key(q, key) ⇒ Object
4728 4729 4730 |
# File 'lib/syntax_tree/node.rb', line 4728 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |