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.
2273 2274 2275 2276 2277 |
# File 'lib/syntax_tree.rb', line 2273 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
2265 2266 2267 |
# File 'lib/syntax_tree.rb', line 2265 def bodystmt @bodystmt end |
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
2271 2272 2273 |
# File 'lib/syntax_tree.rb', line 2271 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
2268 2269 2270 |
# File 'lib/syntax_tree.rb', line 2268 def location @location end |
Instance Method Details
#child_nodes ⇒ Object
2279 2280 2281 |
# File 'lib/syntax_tree.rb', line 2279 def child_nodes [bodystmt] end |
#format(q) ⇒ Object
2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 |
# File 'lib/syntax_tree.rb', line 2283 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
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 |
# File 'lib/syntax_tree.rb', line 2297 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
2308 2309 2310 2311 2312 2313 2314 2315 |
# File 'lib/syntax_tree.rb', line 2308 def to_json(*opts) { type: :begin, bodystmt: bodystmt, loc: location, cmts: comments }.to_json(*opts) end |