Class: SyntaxTree::Begin
- Inherits:
-
Object
- Object
- SyntaxTree::Begin
- Defined in:
- lib/syntax_tree.rb
Overview
Begin represents a begin..end chain.
begin
value
end
Instance Attribute Summary collapse
-
#bodystmt ⇒ Object
readonly
- BodyStmt
-
the bodystmt that contains the contents of this begin block.
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
Instance Method Summary collapse
- #child_nodes ⇒ Object
- #format(q) ⇒ Object
-
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
constructor
A new instance of Begin.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(bodystmt:, location:, comments: []) ⇒ Begin
Returns a new instance of Begin.
2301 2302 2303 2304 2305 |
# File 'lib/syntax_tree.rb', line 2301 def initialize(bodystmt:, location:, comments: []) @bodystmt = bodystmt @location = location @comments = comments end |
Instance Attribute Details
#bodystmt ⇒ Object (readonly)
- BodyStmt
-
the bodystmt that contains the contents of this begin block
2293 2294 2295 |
# File 'lib/syntax_tree.rb', line 2293 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2299 2300 2301 |
# File 'lib/syntax_tree.rb', line 2299 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2296 2297 2298 |
# File 'lib/syntax_tree.rb', line 2296 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
2307 2308 2309 |
# File 'lib/syntax_tree.rb', line 2307 def child_nodes [bodystmt] end |
#format(q) ⇒ Object
2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 |
# File 'lib/syntax_tree.rb', line 2311 def format(q) q.text("begin") unless bodystmt.empty? q.indent do q.breakable(force: true) unless bodystmt.statements.empty? q.format(bodystmt) end end q.breakable(force: true) q.text("end") end |
#pretty_print(q) ⇒ Object
2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 |
# File 'lib/syntax_tree.rb', line 2325 def pretty_print(q) q.group(2, "(", ")") do q.text("begin") q.breakable q.pp(bodystmt) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
2336 2337 2338 2339 2340 2341 2342 2343 |
# File 'lib/syntax_tree.rb', line 2336 def to_json(*opts) { type: :begin, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |