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.



8158
8159
8160
8161
8162
8163
# File 'lib/syntax_tree.rb', line 8158

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



8150
8151
8152
# File 'lib/syntax_tree.rb', line 8150

def block
  @block
end

#callObject (readonly)

Call | Command | CommandCall | FCall

the method call



8147
8148
8149
# File 'lib/syntax_tree.rb', line 8147

def call
  @call
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8156
8157
8158
# File 'lib/syntax_tree.rb', line 8156

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8153
8154
8155
# File 'lib/syntax_tree.rb', line 8153

def location
  @location
end

Instance Method Details

#child_nodesObject



8165
8166
8167
# File 'lib/syntax_tree.rb', line 8165

def child_nodes
  [call, block]
end

#format(q) ⇒ Object



8169
8170
8171
8172
# File 'lib/syntax_tree.rb', line 8169

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

#pretty_print(q) ⇒ Object



8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
# File 'lib/syntax_tree.rb', line 8174

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



8188
8189
8190
8191
8192
8193
8194
8195
8196
# File 'lib/syntax_tree.rb', line 8188

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