Class: SyntaxTree::BareAssocHash

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

BareAssocHash represents a hash of contents being passed as a method argument (and therefore has omitted braces). It’s very similar to an AssocListFromArgs node.

method(key1: value1, key2: value2)

Instance Attribute Summary collapse

Attributes inherited from Node

#location

Instance Method Summary collapse

Methods inherited from Node

#pretty_print, #to_json

Constructor Details

#initialize(assocs:, location:, comments: []) ⇒ BareAssocHash

Returns a new instance of BareAssocHash.



1356
1357
1358
1359
1360
# File 'lib/syntax_tree/node.rb', line 1356

def initialize(assocs:, location:, comments: [])
  @assocs = assocs
  @location = location
  @comments = comments
end

Instance Attribute Details

#assocsObject (readonly)

Array[ Assoc | AssocSplat ]


1351
1352
1353
# File 'lib/syntax_tree/node.rb', line 1351

def assocs
  @assocs
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1354
1355
1356
# File 'lib/syntax_tree/node.rb', line 1354

def comments
  @comments
end

Instance Method Details

#accept(visitor) ⇒ Object



1362
1363
1364
# File 'lib/syntax_tree/node.rb', line 1362

def accept(visitor)
  visitor.visit_bare_assoc_hash(self)
end

#child_nodesObject Also known as: deconstruct



1366
1367
1368
# File 'lib/syntax_tree/node.rb', line 1366

def child_nodes
  assocs
end

#deconstruct_keys(keys) ⇒ Object



1372
1373
1374
# File 'lib/syntax_tree/node.rb', line 1372

def deconstruct_keys(keys)
  { assocs: assocs, location: location, comments: comments }
end

#format(q) ⇒ Object



1376
1377
1378
# File 'lib/syntax_tree/node.rb', line 1376

def format(q)
  q.seplist(assocs) { |assoc| q.format(assoc) }
end

#format_key(q, key) ⇒ Object



1380
1381
1382
# File 'lib/syntax_tree/node.rb', line 1380

def format_key(q, key)
  (@key_formatter ||= HashKeyFormatter.for(self)).format_key(q, key)
end