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
Constructor Details
#initialize(lbrace:, assocs:, location:, comments: []) ⇒ HashLiteral
Returns a new instance of HashLiteral.
4658 4659 4660 4661 4662 4663 |
# File 'lib/syntax_tree/node.rb', line 4658 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
4653 4654 4655 |
# File 'lib/syntax_tree/node.rb', line 4653 def assocs @assocs end |
#comments ⇒ Object (readonly)
[Array[ Comment | EmbDoc ]] the comments attached to this node
4656 4657 4658 |
# File 'lib/syntax_tree/node.rb', line 4656 def comments @comments end |
#lbrace ⇒ Object (readonly)
[LBrace] the left brace that opens this hash
4650 4651 4652 |
# File 'lib/syntax_tree/node.rb', line 4650 def lbrace @lbrace end |
Instance Method Details
#accept(visitor) ⇒ Object
4665 4666 4667 |
# File 'lib/syntax_tree/node.rb', line 4665 def accept(visitor) visitor.visit_hash(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
4669 4670 4671 |
# File 'lib/syntax_tree/node.rb', line 4669 def child_nodes [lbrace] + assocs end |
#deconstruct_keys(keys) ⇒ Object
4675 4676 4677 |
# File 'lib/syntax_tree/node.rb', line 4675 def deconstruct_keys(keys) { lbrace: lbrace, assocs: assocs, location: location, comments: comments } end |
#format(q) ⇒ Object
4679 4680 4681 4682 4683 4684 4685 |
# File 'lib/syntax_tree/node.rb', line 4679 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
4687 4688 4689 |
# File 'lib/syntax_tree/node.rb', line 4687 def format_key(q, key) (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key) end |