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.



8081
8082
8083
8084
8085
8086
# File 'lib/syntax_tree.rb', line 8081

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



8073
8074
8075
# File 'lib/syntax_tree.rb', line 8073

def block
  @block
end

#callObject (readonly)

Call | Command | CommandCall | FCall

the method call



8070
8071
8072
# File 'lib/syntax_tree.rb', line 8070

def call
  @call
end

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



8079
8080
8081
# File 'lib/syntax_tree.rb', line 8079

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



8076
8077
8078
# File 'lib/syntax_tree.rb', line 8076

def location
  @location
end

Instance Method Details

#child_nodesObject



8088
8089
8090
# File 'lib/syntax_tree.rb', line 8088

def child_nodes
  [call, block]
end

#format(q) ⇒ Object



8092
8093
8094
8095
# File 'lib/syntax_tree.rb', line 8092

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

#pretty_print(q) ⇒ Object



8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
# File 'lib/syntax_tree.rb', line 8097

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



8111
8112
8113
8114
8115
8116
8117
8118
8119
# File 'lib/syntax_tree.rb', line 8111

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