Class: SyntaxTree::ArgBlock

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

Overview

ArgBlock represents using a block operator on an expression.

method(&expression)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:, location:, comments: []) ⇒ ArgBlock



1134
1135
1136
1137
1138
# File 'lib/syntax_tree.rb', line 1134

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

Instance Attribute Details

#commentsObject (readonly)

Array[ Comment | EmbDoc ]

the comments attached to this node



1132
1133
1134
# File 'lib/syntax_tree.rb', line 1132

def comments
  @comments
end

#locationObject (readonly)

Location

the location of this node



1129
1130
1131
# File 'lib/syntax_tree.rb', line 1129

def location
  @location
end

#valueObject (readonly)

untyped

the expression being turned into a block



1126
1127
1128
# File 'lib/syntax_tree.rb', line 1126

def value
  @value
end

Instance Method Details

#child_nodesObject



1140
1141
1142
# File 'lib/syntax_tree.rb', line 1140

def child_nodes
  [value]
end

#format(q) ⇒ Object



1144
1145
1146
1147
# File 'lib/syntax_tree.rb', line 1144

def format(q)
  q.text("&")
  q.format(value)
end

#pretty_print(q) ⇒ Object



1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
# File 'lib/syntax_tree.rb', line 1149

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

    q.breakable
    q.pp(value)

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

#to_json(*opts) ⇒ Object



1160
1161
1162
1163
1164
# File 'lib/syntax_tree.rb', line 1160

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