Class: SyntaxTree::BareAssocHash

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree.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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of BareAssocHash.



2196
2197
2198
2199
2200
# File 'lib/syntax_tree.rb', line 2196

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

Instance Attribute Details

#assocsObject (readonly)

Array[ AssocNew | AssocSplat ]


2188
2189
2190
# File 'lib/syntax_tree.rb', line 2188

def assocs
  @assocs
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



2194
2195
2196
# File 'lib/syntax_tree.rb', line 2194

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



2191
2192
2193
# File 'lib/syntax_tree.rb', line 2191

def location
  @location
end

Instance Method Details

#child_nodesObject



2202
2203
2204
# File 'lib/syntax_tree.rb', line 2202

def child_nodes
  assocs
end

#format(q) ⇒ Object



2206
2207
2208
# File 'lib/syntax_tree.rb', line 2206

def format(q)
  q.format(HashFormatter.for(self))
end

#pretty_print(q) ⇒ Object



2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
# File 'lib/syntax_tree.rb', line 2210

def pretty_print(q)
  q.group(2, "(", ")") do
    q.text("bare_assoc_hash")

    q.breakable
    q.group(2, "(", ")") { q.seplist(assocs) { |assoc| q.pp(assoc) } }

    q.pp(Comment::List.new(comments))
  end
end

#to_json(*opts) ⇒ Object



2221
2222
2223
2224
2225
2226
2227
2228
# File 'lib/syntax_tree.rb', line 2221

def to_json(*opts)
  {
    type: :bare_assoc_hash,
    assocs: assocs,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end