Class: SyntaxTree::EndContent
Overview
EndContent represents the use of __END__ syntax, which allows individual scripts to keep content after the main ruby code that can be read through the DATA constant.
puts DATA.read
__END__
Instance Attribute Summary collapse
-
#comments ⇒ Object
readonly
- Array[ Comment | EmbDoc ]
-
the comments attached to this node.
-
#location ⇒ Object
readonly
- Location
-
the location of this node.
-
#value ⇒ Object
readonly
- String
-
the content after the script.
Instance Method Summary collapse
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
- #format(q) ⇒ Object
-
#initialize(value:, location:, comments: []) ⇒ EndContent
constructor
A new instance of EndContent.
- #pretty_print(q) ⇒ Object
- #to_json(*opts) ⇒ Object
Constructor Details
#initialize(value:, location:, comments: []) ⇒ EndContent
Returns a new instance of EndContent.
318 319 320 321 322 |
# File 'lib/syntax_tree/node.rb', line 318 def initialize(value:, location:, comments: []) @value = value @location = location @comments = comments end |
Instance Attribute Details
#comments ⇒ Object (readonly)
- Array[ Comment | EmbDoc ]
-
the comments attached to this node
316 317 318 |
# File 'lib/syntax_tree/node.rb', line 316 def comments @comments end |
#location ⇒ Object (readonly)
- Location
-
the location of this node
313 314 315 |
# File 'lib/syntax_tree/node.rb', line 313 def location @location end |
#value ⇒ Object (readonly)
- String
-
the content after the script
310 311 312 |
# File 'lib/syntax_tree/node.rb', line 310 def value @value end |
Instance Method Details
#child_nodes ⇒ Object Also known as: deconstruct
324 325 326 |
# File 'lib/syntax_tree/node.rb', line 324 def child_nodes [] end |
#deconstruct_keys(keys) ⇒ Object
330 331 332 |
# File 'lib/syntax_tree/node.rb', line 330 def deconstruct_keys(keys) { value: value, location: location, comments: comments } end |
#format(q) ⇒ Object
334 335 336 337 338 339 340 |
# File 'lib/syntax_tree/node.rb', line 334 def format(q) q.text("__END__") q.breakable(force: true) separator = -> { q.breakable(indent: false, force: true) } q.seplist(value.split(/\r?\n/, -1), separator) { |line| q.text(line) } end |
#pretty_print(q) ⇒ Object
342 343 344 345 346 347 348 349 350 351 |
# File 'lib/syntax_tree/node.rb', line 342 def pretty_print(q) q.group(2, "(", ")") do q.text("__end__") q.breakable q.pp(value) q.pp(Comment::List.new(comments)) end end |
#to_json(*opts) ⇒ Object
353 354 355 356 357 |
# File 'lib/syntax_tree/node.rb', line 353 def to_json(*opts) { type: :__end__, value: value, loc: location, cmts: comments }.to_json( *opts ) end |