Class: SyntaxTree::MethodAddBlock

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

Overview

MethodAddBlock represents a method call with a block argument.

method {}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(call:, block:, location:, comments: []) ⇒ MethodAddBlock

Returns a new instance of MethodAddBlock.



8290
8291
8292
8293
8294
8295
# File 'lib/syntax_tree.rb', line 8290

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

Instance Attribute Details

#blockObject (readonly)

BraceBlock | DoBlock

the block being sent with the method call



8282
8283
8284
# File 'lib/syntax_tree.rb', line 8282

def block
  @block
end

#callObject (readonly)

Call | Command | CommandCall | FCall

the method call



8279
8280
8281
# File 'lib/syntax_tree.rb', line 8279

def call
  @call
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8288
8289
8290
# File 'lib/syntax_tree.rb', line 8288

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8285
8286
8287
# File 'lib/syntax_tree.rb', line 8285

def location
  @location
end

Instance Method Details

#child_nodesObject



8297
8298
8299
# File 'lib/syntax_tree.rb', line 8297

def child_nodes
  [call, block]
end

#format(q) ⇒ Object



8301
8302
8303
8304
# File 'lib/syntax_tree.rb', line 8301

def format(q)
  q.format(call)
  q.format(block)
end

#pretty_print(q) ⇒ Object



8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
# File 'lib/syntax_tree.rb', line 8306

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

    q.breakable
    q.pp(call)

    q.breakable
    q.pp(block)

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

#to_json(*opts) ⇒ Object



8320
8321
8322
8323
8324
8325
8326
8327
8328
# File 'lib/syntax_tree.rb', line 8320

def to_json(*opts)
  {
    type: :method_add_block,
    call: call,
    block: block,
    loc: location,
    cmts: comments
  }.to_json(*opts)
end